C#改变窗口样式

#region 改变窗口样式

        #if !DEBUG

        [DllImport ("User32.dll")]         private static extern IntPtr GetWindowDC(IntPtr hwnd);

        [DllImport ("User32.dll")]         private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);

        protected  override  void WndProc(ref Message m)         {                 base.WndProc(ref m);                          switch(m.Msg)                 {

                    case 0x86://WM_NCACTIVATE

                        goto case 0x85;

                    case 0x85://WM_NCPAINT                     {                                                           IntPtr hDC = GetWindowDC(m.HWnd);                              //把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了                         Graphics gs = Graphics.FromHdc(hDC);

                        处理色彩#region 处理色彩

                        int ibox = 1;

                        if (this.MaximizeBox) ibox ++;                         if (this.MinimizeBox) ibox ++;

                        //得到相关背景图片                         Image imgpm =  Image.FromFile( Application.StartupPath+ @"Main.bmp");                        //gs.DrawImage(imgbg,3,0,this.Width - (ibox * iBoxWidh),SystemInformation.CaptionHeight + 2); //显示

背景图片                         //标题栏显示背景颜色                         int xPos    = this.Width    -    iBoxWidh * ibox - 2 - ibox*3;

                        Rectangle excludeRect;                         //标题栏中不需要填充的位置                         for(int i=0;i<ibox;i++)                         {                             if( i>0)                             {                                 xPos = xPos +  iBoxWidh + 2;                             }                                                            excludeRect = new Rectangle(xPos, 5, iBoxWidh, iBoxWidh+1);                             gs.ExcludeClip(excludeRect);                         }                                                 //背景区域                         Rectangle rBackground = new Rectangle(0,0,this.Width,SystemInformation.CaptionHeight+3);                         //背景颜色 上下渐变                         System.Drawing.Drawing2D.LinearGradientBrush bBackground                             = new System.Drawing.Drawing2D.LinearGradientBrush(rBackground, Color.FromArgb(100,145,175),

Color.FromArgb(45,80,120),LinearGradientMode.Vertical);                           //标题栏填充背景颜色                         gs.FillRectangle(bBackground,rBackground );                         //显示图标文件                      gs.DrawImage(imgpm,4,4,24,24);   

                        #endregion

                        StringFormat strFmt = new StringFormat();

                        //strFmt.Alignment = StringAlignment.Center;                         //strFmt.LineAlignment = StringAlignment.Center;

                        //gs.DrawString(this.Text, this.Font, Brushes.BlanchedAlmond, m_rect, strFmt);                         //设置标题字体                         Font drawFont = new Font("宋体", 10,System.Drawing.FontStyle.Bold);                         //设置标题颜色                         SolidBrush drawBrush = new SolidBrush(Color.White);                                              //重画标题                         gs.DrawString(this.Text, drawFont, drawBrush, 30,8);

                        gs.Dispose();

                        //释放GDI资源

                        ReleaseDC(m.HWnd, hDC);                                                  break;

                    }

                    case 0xA1://WM_NCLBUTTONDOWN                     {                         Point mousePoint = new Point((int)m.LParam);

                        mousePoint.Offset(-this.Left, -this.Top);

                        //if(m_rect.Contains(mousePoint))                         //{                         //                         //   MessageBox.Show("hello");                         //                         //}

                        break;                     }                 }             }                  #endif

        #endregion

C# 窗体应用程序中,可以使用 `ProgressBar` 控件来显示进度条。要改变进度条的样式,可以使用 `Style` 属性和自定义的外观来实现。以下是一种常见的方法: 1. 在窗体设计器中,将 `ProgressBar` 控件拖放到窗体上。 2. 选中进度条控件,在属性窗口中找到 `Style` 属性。 3. 可以选择以下几种样式之一: - `Blocks`:块状样式,进度条被块状分割。 - `Continuous`:连续样式,进度条是一个连续的线条。 - `Marquee`:滚动样式,进度条将以滚动的方式显示。 4. 根据你的需求选择适合的样式。你还可以通过其他属性来改变进度条的外观,如 `ForeColor`、`BackColor`、`Value` 等。 如果你需要更加自定义的样式,可以考虑使用自定义绘制来实现。以下是一个示例代码,展示如何使用自定义绘制来改变进度条的样式: ```csharp using System; using System.Drawing; using System.Windows.Forms; namespace ProgressBarExample { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void MainForm_Paint(object sender, PaintEventArgs e) { // 自定义绘制进度条外观 ProgressBarRenderer.DrawHorizontalBar(e.Graphics, ClientRectangle); Rectangle progressBounds = new Rectangle(ClientRectangle.X, ClientRectangle.Y, (int)(ClientRectangle.Width * (progressBar.Value / 100.0)), ClientRectangle.Height); ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, progressBounds); } } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } } ``` 在上面的示例中,我们在 `MainForm_Paint` 事件处理程序中自定义绘制了进度条的外观。我们通过 `ProgressBarRenderer` 类的静态方法来绘制进度条的背景和进度。你可以根据需要自定义绘制的样式,例如改变进度条的颜色、形状等。 请注意,上述代码是在 Windows 窗体应用程序中使用的示例。你需要创建一个新的 Windows 窗体应用程序项目,并将代码放置在主窗体类中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值