C#窗体深入设计问题_高手请进(觉得挺难的)
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;
linkLabel17.Text = info;
linkLabel14.Text = info;
linkLabel16.Text = info;
linkLabel18.Text = info;
rtbpersonality.Text=info;
rtbvirtue.Text=" " +info;
rtbflaw.Text=" "+info;
}
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;
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>birthday)
{
strConstellation=atoms;
break;
}
}
return strConstellation;
}
#endregion
}
}
中间的代码你们可以忽略,主要是想实现当月份修改时,同步修改天数的combobox选择值,看图片,比如说我选择了2月,那么我的天数的选择框上的内容就应该是28,这个想法理论上是可以成功的,但是为什么我这个代码却无法做到这一点呢?
首先声明:我已经试着在我的text上输出了我所捕获的月份的数值,该数值是没有错误的,能正确的捕获到是1~12的数值,问题在于能捕获但是无法修改天数的选择框上的范围。
哦,顺便补充一句,问题在调试阶段的那个代码,还有……图片在这里 晚上回来给你远程,你早点发贴的话昨天晚上就给你弄了 (Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 400== 0) || (Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 100) != 0)&&(Convert.ToInt32(cbbYear.SelectedItem.ToString()) % 4== 0) 什么?这个是条件语句,没错的啊 不好意思,打扰大家了,关于这个问题我已经解决了,原因在于我还不懂事件的运用。。。 谢谢分享!!! 谢谢分享!!!
页:
[1]