美文网首页
winform 窗体控件小结

winform 窗体控件小结

作者: 球球1104 | 来源:发表于2017-02-15 16:57 被阅读0次

1.固定頁面大小:FormBorderStyle选项,选择FixedDialog
2.多行滚动条:ScrollBars, V是竖, H是横
3.如何在textbox输入完成之后,按回车相当于点击了button按钮

7.png
4.Textbox:
添加:
          name =txtusername.Text;//获取輸入的name值
          txtusername.Text = dr["UserName"].ToString();
         //将第一行列表名为UserName的值赋给user对象的UserName属性

清空:

         txtusername.Text = "";//设置空置,进行清空

多行显示:

        txtusers.AppendText(users[i] + Environment.NewLine);
        //注意!使用 Environment.NewLine 实现换行textBox1.AppendText(显示的内容 + Environment.NewLine);

5.Listbox:
ListBox控件显示较长的选项列表,用户可从中选择一项或多项。如果项总数超出可以显示的项数,则自动向ListBox控件添加滚动条。ListBox控件列表中的每个元素称为项。
说明:
① 该属性使用户可以获取对当前存储在 ListBox 中的项列表的引用。通过此引用,可以在集合中添加项、移除项和获得项的计数。
② 可以使用DataSource属性来操控ListBox的项。如果使用DataSource属性向ListBox添加项,则可以使用Items属性查看ListBox中的项,但不能使用ListBox.ObjectCollection的方法向该列表添加项或从中移除项。

代码示例:

           SqlConnection con = new SqlConnection("server=12;uid=sa;pwd=;database=test");
           con.Open();
           SqlCommand com = new SqlCommand("select * from table",con);
           SqlDataReader dr = com.ExecuteReader();
           this.listBox1.Items.Clear();
           while (dr.Read())
           {
           // this.listBox1.Items.Add(dr[0].ToString());
           this.listBox1.Items.Add(dr[1].ToString());
           //   this.listBox1.Items.Add(dr[2].ToString());
           }
           dr.Close();
           cn.Close();

多行显示:

          listBox1.Items.Add(Administrators[i]);

清空:

            listBox1.Items.Clear();

每次添加的的数据都要在上一次添加的下面,就像QQ聊天一样,发送的文字总是在上一次发送的下面: listBox1.Items.Add(DateTime.Now.ToString());类似这样就可以了

6.tabcontrol
属性:Dock居中
关于复写标签颜色:
#region 控制Table選項的顏色
//C#改变TabControl标签颜色和字体
//1.在Form类的构造函数中添加下列语句:
//this.MainBook.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
//this.MainBook.DrawItem += new DrawItemEventHandler(this.MainBook_DrawItem);
/// <summary>
/// 控制Table選項的顏色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainBook_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.MainBook.SelectedIndex)
{
//fntTab = new Font(e.Font, FontStyle.Bold);
fntTab = new Font(e.Font, FontStyle.Regular);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.ControlLight, SystemColors.ControlLight, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshFore = Brushes.Black;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(Color.SteelBlue);
bshFore = new SolidBrush(Color.Yellow);
}
string tabName = this.MainBook.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X + 8, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
#endregion

7.richTextBox1
支持輸出內容自己自動換行
Textbox
也支持自動換行,但是不支持\n
8.webBrowser控件
在Url中輸入路徑(將文件保存爲mht格式).可以展示一些用戶使用手冊云云

相关文章

  • winform 窗体控件小结

    1.固定頁面大小:FormBorderStyle选项,选择FixedDialog2.多行滚动条:ScrollBar...

  • 11.6

    今天,老师继续讲解了winform的模式与非模式窗体,image控件,定时器控件,滚动条控件,还是要多了解谢谢控件...

  • 11月2日四期C#总结

    今天我们学习了第四章的WinForm、窗口的基本控件、窗体、委托。 Form类定义了窗体的基本属性和行为 ...

  • 01-Form窗体

    Windows应用程序也称为WinForm应用程序,通常包含一个或多个窗体,窗体中又包含了多种控件,如按钮、文本框...

  • c#自定义窗体

    我想美化窗体或者是其他控件、无外乎三种方式: 1、重写WinForm自带的控件,这需要熟练掌握GDI+ 技术、并且...

  • 2017 11 02

    今天老师首先复习了第4章的内容,然后讲解了第七章控件 新的内容有WinForm,窗口的基本控件,窗体、委托 Win...

  • 11.2学习总结

    今天对第四章进行了一个总的复习,开始学了第七章控件。 具体是 认识和添加窗体类。 WinForm窗体的属性方法、事...

  • WPF窗体加载Winform控件不显示

    最近在做一个WPF项目,有一个功能是这样的,自定义的无边框窗体,一开时设置了AllowsTransparency=...

  • WinForm 父子窗体调用方法和控件

  • 11月2日-4期C语言学习总结

    总结:今天老师把之前的课程简单的温习一遍,并从第七章开始讲新的内容。主要学习了WinForm的窗体,还有控件的使用...

网友评论

      本文标题:winform 窗体控件小结

      本文链接:https://www.haomeiwen.com/subject/kbmqwttx.html