当前位置:编程学习 > C#/ASP.NET >>

C# windows 编程 多选按钮的实现


               string Tsql="";
           
                if (check_xinxi_name.Checked == true)
                {
                     Tsql =string.Format ("userName='{0}'",txt_xinxi_name .Text.Trim ());
                     
                }
                if (check_xinxi_num.Checked == true)
                {
                    Tsql = string.Format("Student_id='{0}'", txt_xinxi_num.Text.Trim());
                }
                if (checkB_xinxi_fasten.Checked == true)
                {
                    Tsql = string.Format("fasten='{0}'",combo_xinxi_fasten.Text.Trim ());
                }
                if (checkb_xixin_layer.Checked == true)
                {
                     Tsql = string.Format("layer='{0}'" , comb_xinxi_layer.Text.Trim() );
                }
                if (check_xinxi_class.Checked == true)
                {
                     Tsql = string.Format("class='{0}'",comboB_xinxi_class.Text.Trim());
                }
                if (checkBo_phone.Checked == true)
                {
                     Tsql = string.Format("phone='{0}'", txt_xinxi_phone.Text.Trim() );
                }
               // string Tsqls="";
               // Tsqls +=Tsql;
               try
               {
                   DB.testConnection.Open();
                   string str = string.Format("select * from student_Information_registration where " + Tsql + "");
                   SqlCommand cmd = new SqlCommand(str, DB.testConnection);
                   SqlDataAdapter da = new SqlDataAdapter(cmd);
                   DataSet ds = new DataSet();
                   da.Fill(ds);
                   dataGridView3.DataSource = ds.Tables[0];
                   DB.testConnection.Close();
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }
               finally
               {
                   DB.testConnection.Close();
               }

里面还要添加什么代码才能实现多选呢!

追问:C#   哈 能不能用C#  给我写呢
答案:在Winform中的打印主要可以通过三种方式来实现:一种是使用Winform提供的类,另一种是使用控件,还有一种就是利用水晶报表的打印。
打印控件主要优势是方便快捷,一般应用于简单、固定、单调的模板打印,其主要常用控件有:
(1) PrintDocument:是一个可用于设置属性来描述有关打印的信息,并且可用于调用方法Print()或通过事件PrintPage来打印文档的组件。
(2) PrintDialog:允许用户选择打印机并指定文档中要打印的部分。
(3) PrintPreviewDialog:此控件是一个打印预览对话框,用于显示文档的打印效果。该控件包含用于打印、放大、显示一页或多页以及关闭对话框的按钮。
(4) PageSetupDialog:主要用来设置页面大小,页边距等。
------------------------------------------------------
建个winform工程,拖如上四个控件,再拖三个按钮
public Form1()
{
InitializeComponent();
this.printDialog1.Document = this.printDocument1;//必要的
this.printPreviewDialog1.Document = this.printDocument1;
this.pageSetupDialog1.Document = this.printDocument1;
}

private void button3_Click(object sender, EventArgs e)
{//打印
if (this.printDialog1.ShowDialog() == DialogResult.OK)
this.printDocument1.Print();
}

private void button1_Click(object sender, EventArgs e)
{//打印预览
this.printPreviewDialog1.ShowDialog();
}

private void button2_Click(object sender, EventArgs e)
{//打印设置
this.pageSetupDialog1.ShowDialog();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{//双击printDocument控件,这才是真正开始干活的,在这里面写你想要打印信息
Font font = new Font("Tahoma", 12, FontStyle.Underline);//设置画笔
Brush bru = Brushes.Blue;
Pen pen = new Pen(bru);
pen.Width = 5;
//设置各边距
int nLeft = this.pageSetupDialog1.PageSettings.Margins.Left;
int nTop = this.pageSetupDialog1.PageSettings.Margins.Top;
int nRight = this.pageSetupDialog1.PageSettings.Margins.R


如果帮助到您,请记得采纳为满意答案哈,谢谢!祝您生活愉快!

参考资料: http://vae.la

Private Sub Command1_Click()
if check1.value=-1 then
选中时的代码
else
没选中的代码
end if
end sub
不明白!!!!!!!1

楼主你好,很高兴为你解答有关C#方面的问题。

    不知道楼主是不是想实现____:根据用户的选择去数据库中查询相对应的信息。

 (比如说QQ的好友查询模式。根据用户选择的年龄段和性别去查询)

如果是的话。那么你的代码的改善下。每一个if下。不能给变量Tsql赋新值,使用字符串的连接可以

实现上述效果。

如果能帮楼主解决问题。请采纳。如果楼主还有什么疑问,请加3 0 9 1 4 0 4 0 0

竭诚为您解答。

上一个:C# 窗口失去焦点时关闭如何实现?
下一个:C# 如何在提取SQL数据!内详

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,