c#Winform程序的toolStripButton自定义背景应用示例源码

C# Winform程序的toolStrip中toolStripButton的背景是蓝色的,如何改变背景及边框的颜色和样式呢?

实现此功能需要重写toolStripButton的Paint方法

这里只是给出解决问题的思路和方法,如下图,当鼠标移到按钮上,背景会变为黑色


实现代码如下:

            ToolStripButton tsb = (ToolStripButton)sender;

            Rectangle rectButton = tsb.Bounds;
            Point p = toolStrip1.PointToClient(Control.MousePosition);
            if (rectButton.Contains(p))
            {
                e.Graphics.Clear(SystemColors.ControlText);
                if (tsb.Image != null)
                {
                    e.Graphics.DrawImage(tsb.Image, new Point((e.ClipRectangle.Width - tsb.Image.Width) / 2, (e.ClipRectangle.Height - tsb.Image.Height) / 2));
                }
            }
源码下载: c#Winform程序的toolStripButton自定义背景应用示例源码

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在C# Winform中嵌入基恩士应用程序exe,可以使用Process类来启动应用程序,并将其嵌入到窗体中。以下是实现步骤: 1. 打开Visual Studio中的Winform项目,并在工具箱中添加一个Panel控件。 2. 在代码中使用Process类的Start方法来启动基恩士应用程序exe,并将其嵌入到Panel控件中。 3. 设置基恩士应用程序exe的属性和方法,以便与其进行交互。 以下是代码示例: ```csharp using System.Diagnostics; using System.Windows.Forms; namespace WinformApp { public partial class Form1 : Form { private Process process; public Form1() { InitializeComponent(); // 启动基恩士应用程序exe process = new Process(); process.StartInfo.FileName = "KeenShine.exe"; process.StartInfo.Arguments = ""; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); // 将基恩士应用程序exe嵌入到Panel控件中 process.WaitForInputIdle(); SetParent(process.MainWindowHandle, panel1.Handle); // 设置窗体大小和位置 process.StartInfo.WindowStyle = ProcessWindowStyle.Normal; process.WaitForInputIdle(); MoveWindow(process.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true); // 设置基恩士应用程序exe的属性和方法 process.StandardInput.WriteLine("Command1"); var result = process.StandardOutput.ReadLine(); // ... } protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); // 关闭基恩士应用程序exe process.Kill(); } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll")] private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint); } } ``` 在上面的代码中,panel1是Winform中的一个Panel控件,用来显示基恩士应用程序exe。你需要根据实际情况设置基恩士应用程序exe的属性和方法。需要注意的是,在关闭窗体时,需要使用Process类的Kill方法来关闭基恩士应用程序exe。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值