visualstdioC#编码小知道

本文档详细介绍了Windows窗体应用程序的基础操作,包括如何创建、显示和关闭窗体,以及如何使用各种控件如按钮、文本框等进行界面设计。此外还讲解了文件对话框的应用、定时器控件的配置等高级功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Application.Exit();//关闭整个应用程序。
//打开另一个子窗口
    项目name a = new 项目name();
          无模式窗口  a.Show(); a.visible = ture;        ///////   有模式窗口a.ShowDialog();


------------------------------------
关闭窗口
this close();
隐藏窗体  
a.visible = false;


------------------------------------------








控件 Openfiledialog


//show the open file dialog box.打开文件会话框
            (控件的名字Openfiledialog.ShowDialog()==DialogResult.OK)


-------------------


//将图片存入图片对话框里
            图片框name.Image = Image.FromFile(控件的name Openfiledialog.FileName);


--------------------------------


//show the name of the file in the form's caption 动态应用,不断调整属性
                this.Text = string.Concat("窗口的textname(" + 控件的name Openfiledialog.FileName + ")");




--------------------------------------------
     //创建一个变量
        string strFirstName;






       //不返回值的过程
            public void MyProcedure()
         {
            //过程代码


         }




       //返回值的过程
            public string AuthorName()
         {
            //过程代码
          ruturn "   "; 


         }


  
       //返回值的过程中接受参数
            public string AuthorName( string BookName)
         {
            //过程代码
          ruturn "   "; 


         }


------------------------------------------
           // 消息框
         MessageBox.Show("");






--------------------------------------------------------
          //Click改变窗口大小


            this.Width = this.Width - 20;
             this.Height = this.Height - 20;




---------------------------------
      //触发方法
        对象name.方法();
-------------------------------
   //封装画图
   Graphics 变量名字 = null;
            变量名字 = this.CreateGraphics();
        变量名字 .Clear(SystemColors.Control);
      变量名字.DrawRectangle(Pens.Blue,
               涂画框name.Left - 1, picShowPicture.Top - 1,
                picShowPicture.Width + 1, picShowPicture.Height + 1);
 -----------------------------------
 //清理工作
          变量名.Dispose();




      //销毁对象
        变量名.Dispose();




---------------------------------------
       //看有多少个组件
            for(int intIndex =0;intIndex < this.Controls.Count;intIndex++)
            {
                MessageBox.Show("Control #" + intIndex.ToString() +
                "has the name" + this.Controls[intIndex].Name);
            }
  
            
 -----------------------------------------          
     //光标坐标显示
    名字lblX.Text = "X: " + e.X.ToString();
            lblY.Text = "Y: " + e.Y.ToString();


   //初始化标签load事件中
            lblX.Text = " ";
            lblY.Text = " ";
------------------------------------------------


-------------------------




-------------------------------
窗体的属性     controlbox 设置为false,隐藏关闭缩小,放大


焦点窗口      属性topmost
透明属性       opacity
滚动条         autoscroll




窗口变为父窗口 ismdicontainer
父窗体中
fclsChild_1 objChild = new fclsChild_1();
            objChild.MdiParent = this;
            objChild.Show();
子窗体中click事件
fclsChild_2 objChild = new fclsChild_2();
            objChild.MdiParent = this.MdiParent;
            objChild.Show();






文本框调整 multiline
scrollbars增加滚动条
acceptreturn 可使用户按回车键
maxlength 限制用户输入的数字
passwordchar 设置密码字段
grop box 用来显示长的说明文字 分组框






listbox列表框  items操作集合
    增加  列表name.Items.Add("DSDFDFSFFDFF");
    特定位置增加  列表名字.Items.Insert(0,"DSDFDFSFFDFF"); 
    删除       列表名字.Items.Remove("123");
    删除       列表名字.Items.RemoveAt(0);
    清除所有  列表名字.Items.Clear();
    MessageBox.Show("You selected" + 列表名.SelectedItems +
                "which has an index of" + 列表名.SelectedIndex);
sorted 强制排序
















check box用来复选框
radiobutton 单选框
combobox  选择列表框   dropdownstyle改为 ····list限制输入








timer控件  enabled值改为ture  interval决定触发间隔时间
 //ToLongTimeString();以hh:mm:SS以字符串的形式返回
           labl的名字.Text = DateTime.Now.ToLongTimeString();








带标签页的对话框
tapcontrol   tabpages










imagelist  存储图像并被其他控件所用




list view可创建简单的列表,多列网格,图标托盘
columns列集合
属性fullrowselect










menustrip  main menu控件
     //设置与当前的cheek相反的值
            mnuConfirmOnExit.Checked = !(mnuConfirmOnExit.Checked);


context menu strip   右键菜单


toolstrip 工具栏




statusstrip菜单工具栏
 














---------------------




private void ···()
{}




返回值 Private int 方法名(参数  string....)
{
return ...Length;     
}












定义常量
const 数据类型 常数名 = 值































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子非鱼.li

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值