C#学习总结(慢慢更新中)

 

1.  窗体的opacity属性可以实现窗体的渐显效果,窗体的TopMost属性this.TopMost=True可以是程序始终在前面.

2.  通过设置PictureBox的Dock属性和添加spliter控件可以实现窗体的分割.

3.  C#中添加API函数的方法,以SetMenuItemBitmaps为例子

[System..Runtime.Interopservices.DllImport(“user 32” )]

Private static  extern int SetMenItemBitmaps{Intptr hMenu,int nPosition,int wFlags,IntPtr hBitmapUnchecked,IntPtr hBitmapChecked };

Const int MF_BYPOSITION=0x0400;

4. 实现渐变窗口背景的方法

   添加System.Drawing.Drawing2D空间的引用

   private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

         {

              Graphics g=e.Graphics ;

              Color fcolor=Color.Blue ;

              Color Tcolor=Color.Yellow ;

     Brush b=new LinearGradientBrush (this.ClientRectangle ,fcolor,Tcolor,LinearGradientMode.ForwardDiagonal );

              g.FillRectangle (b,this.ClientRectangle );

         }

 

         private void Form1_Resize(object sender, System.EventArgs e)

         {

              this.Invalidate ();

         }

5.通过添加NotifyIconContestMenu组件可以实现状态栏的状态区的使用.

参考代码:

static void Main ()

         {

              Form 1 f 1=new Form1 ();

              f1.notifyIcon1 .Icon =new System .Drawing .Icon ("..//..//BICYCLE.ICO");

              f1.notifyIcon1 .Visible =true;

              f1.notifyIcon1 .Text ="BICYCLE";

              Application.Run ();

         }

 

         private void menuItem1_Click(object sender, System.EventArgs e)

         {

              Application.Exit ();

         }

private void timer1_Tick(object sender, System.EventArgs e)

         {

              if(notifyIcon1.Text =="BICYCLE")

              {

                   notifyIcon1.Icon =new System .Drawing .Icon ("..//..//CARS.ICO");

                   notifyIcon1.Text ="CARS";

}

              else

              {

                   notifyIcon1.Icon =new System .Drawing .Icon ("..//..//BICYCLE.ICO");

                   notifyIcon1.Text ="BICYCLE";

              }

         }

6.使用StatusBar控件实现状态栏信息的更新

参考代码:

private void Form1_Load(object sender, System.EventArgs e)

         {

              statusBar1.Panels .Add ("one");

              statusBar1.Panels [0].AutoSize =StatusBarPanelAutoSize.Spring ;

              statusBar1.Panels [0].Icon =new System .Drawing .Icon ("..//..//app.ico");

              statusBar1.Panels [0].BorderStyle =StatusBarPanelBorderStyle.Sunken;

              statusBar1.ShowPanels =true;

 

         }

 

         private void timer1_Tick(object sender, System.EventArgs e)

         {

              statusBar1.Panels [0].Text =DateTime.Now .ToString ();

         }

     }

7.C#中使用动画光标的方法

使用SetCursorLoadCursorFromFile二个API函数,

参考代码:

[DllImport("user32")]

              private static extern IntPtr SetCursor(IntPtr hCursor);

         [DllImport("user32")]

              private static extern IntPtr LoadCursorFromFile(string lpFileName);

         const int WM_SETCURSOR=0X0020;

         protected override void WndProc(ref System.Windows .Forms .Message  m)

         {

              switch(m.Msg )

              {

                   case WM_SETCURSOR:

                       IntPtr hCursor;

                       hCursor=LoadCursorFromFile("..//..//1.ani");

                       SetCursor(hCursor);

                       break;

                   default:

                       base.WndProc (ref m);

                       break;

              }

         }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值