马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C#窗体深入设计问题_高手请进(觉得挺难的)

  [复制链接]
查看6358 | 回复7 | 2013-3-15 00:02:01 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace 星座查询器
{
   
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        #region button1_Click
        private void button1_Click(object sender, EventArgs e)
        {
           try
           {
               DateTime dt=new DateTime(1,Convert.ToInt32(cbbMonth.SelectedItem.ToString()),Convert.ToInt32(cbbDay.SelectedItem.ToString()));
               linkLabel13.Text = Search.GetConstellation(dt);
               string[] info =Search.ConstellationDescription(Search.GetConstellation(dt));
               linkLabel15.Text = info[0];
               linkLabel17.Text = info[1];
               linkLabel14.Text = info[2];
               linkLabel16.Text = info[3];
               linkLabel18.Text = info[4];
               rtbpersonality.Text=info[5];
               rtbvirtue.Text="      " +info[6];
               rtbflaw.Text=  "      "+info[7];
           }
            catch
           {
                MessageBox.Show("选择的日期有误!","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }
#endregion
        #region   初始化月份下拉菜单_调试阶段
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 1900; i <= 2100; i++)
                cbbYear.Items.Add(i.ToString());
            cbbYear.SelectedIndex = 100;
            for (int i = 1; i <= 12; i++)
                cbbMonth.Items.Add(i.ToString());
            cbbMonth.SelectedIndex = 2;
            int days=31;
            int number=Convert.ToInt32(cbbMonth.SelectedItem.ToString());
            rtbflaw.Text = number.ToString();   //显示所捕获的月份
            switch (Convert.ToInt32(cbbMonth.SelectedItem.ToString()))
            {
                case 1:
                case 3:
                case 5:
                case 8:
                case 10:
                case 12:
                case 7: days = 31; break;
                case 4:
                case 6:
                case 9:
                case 11: days = 30; break;
                case 2: if ((Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 4 == 0) && ((Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 100) != 0))
                        {days = 29; break;}
                    else{days = 28; break;}
                default: MessageBox.Show("没有处理的switch命令", "警告"); break;
            }
            for (int j = 1; j <= days; j++)
                cbbDay.Items.Add(j.ToString());
            cbbDay.SelectedIndex=0;
        }
        #endregion
        #region button2_Click
        private void button2_Click(object sender, EventArgs e)
       {
           linkLabel15.Text ="***";
           linkLabel17.Text = "***";
           linkLabel14.Text = "***";
           linkLabel16.Text = "***";
           linkLabel18.Text = "***";
           rtbpersonality.Text = "";
           rtbvirtue.Text = "";
           rtbflaw.Text = "";
       }
        #endregion
    }
        public class Search
        {
            /// <summary>
            /// 根据星座返回相应的星座特色、幸运色、幸运数字、幸运日、幸运地点
            /// 个性特征、优点、缺点
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            #region   ConstellationDescription   
            public static string[] ConstellationDescription(string str)
            {
                string[] Description = new string[8];
                if (str != "")
                {
                    switch (str)
                    {
                       //忽略该内容(为星座的信息,与结果不相关)
                        default: MessageBox.Show( "您选择的信息有误!请重新输入!","警告"); break;
                    }
                }
                return Description;   
               
            }
#endregion
            #region GetConstellation
            public static string GetConstellation(DateTime strBirthday)
           {
                string strConstellation=null;
                float birthday=0.00F;
                if(strBirthday.Month==1&&strBirthday.Day<20)
                {
                    birthday=float.Parse(string.Format("13.{0}",strBirthday.Day));
                }
                else
                {
                    if(strBirthday.Day<10)
                        birthday=float.Parse(string.Format("{0}.0{1}",strBirthday.Month,strBirthday.Day));
                    else
                        birthday=float.Parse(string.Format("{0}.{1}",strBirthday.Month,strBirthday.Day));
                }
                float[] atomBound = { 1.20F, 2.20F, 3.21F, 4.21F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.23F, 11.21F, 12.22F,13.20F};
                string[] atoms={@"水瓶座","双鱼座","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天平座","天蝎座"
                                   ,"射手座","摩羯座"};
                for(int i =0;i<atomBound.Length-1;i++)
                {
                    if(atomBound<=birthday&&atomBound[i+1]>birthday)
                    {
                        strConstellation=atoms;
                        break;
                    }
                }
                return strConstellation;
            }
            #endregion
        }        
}
中间的代码你们可以忽略,主要是想实现当月份修改时,同步修改天数的combobox选择值,看图片,比如说我选择了2月,那么我的天数的选择框上的内容就应该是28,这个想法理论上是可以成功的,但是为什么我这个代码却无法做到这一点呢?
首先声明:我已经试着在我的text上输出了我所捕获的月份的数值,该数值是没有错误的,能正确的捕获到是1~12的数值,问题在于能捕获但是无法修改天数的选择框上的范围。

IoveBC | 2013-3-15 00:03:37 | 显示全部楼层
哦,顺便补充一句,问题在调试阶段的那个代码,还有……图片在这里
QQ截图20130314235436.png
ibcadmin | 2013-3-15 08:52:23 | 显示全部楼层
晚上回来给你远程,你早点发贴的话昨天晚上就给你弄了
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
qzuser | 2013-3-16 13:55:00 | 显示全部楼层
(Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 400== 0) || (Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 100) != 0)&&(Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 4== 0)
IoveBC | 2013-3-17 16:11:45 | 显示全部楼层
什么?这个是条件语句,没错的啊
IoveBC | 2013-3-24 10:00:29 | 显示全部楼层
不好意思,打扰大家了,关于这个问题我已经解决了,原因在于我还不懂事件的运用。。。
chao2332601 | 2013-6-16 00:48:11 | 显示全部楼层
谢谢分享!!!
chao2332601 | 2013-6-16 04:41:32 | 显示全部楼层
谢谢分享!!!
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则