重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1.在mouse事件中实现
创新互联公司2013年至今,是专业互联网技术服务公司,拥有项目网站制作、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元宝清做网站,已为上家服务,为宝清各地企业和个人服务,联系电话:13518219792
2.调用windows API
实现方式为:
1.在mouse事件中实现
[csharp] view plain copy
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标签是否为左键
private void groupControl1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
private void groupControl1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
2.调用windows API
调用前需要添加using System.Runtime.InteropServices;
[csharp] view plain copy
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture(); //释放鼠标捕捉
//发送左键点击的消息至该窗体(标题栏)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
花了二十分钟给你写了代码,已测试。建议学习并使用System.Drawing绘制。
主要是掌握Graphics.FillRectangle和DrawString的使用。
Imports System.Drawing
Public Class 进度条UI
Public 上面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 175, 238, 238))
Public 下面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 30, 144, 255))
Public 文字笔 As SolidBrush = New SolidBrush(Color.FromArgb(255, 255, 255, 255))
Public 字体 As Font = New Font("微软雅黑", 14.0)
Public 文字格式 As StringFormat = New StringFormat() With
{.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
''' summary
''' 绘制指定进度的图像。
''' 当进度变化时调用一次本方法,建议将创建的Graphics对象保存到变量而不要重复创建。。
''' /summary
''' param name="控件"绘制到此控件的工作区/param
''' param name="g"绘制到控件的Graphics对象,例如 Button1.CreateGraphics()/param
''' param name="进度"进度百分比实数,57% = 0.57/param
Public Sub 绘制(ByRef 控件 As Control, ByRef g As Graphics, ByVal 进度 As Double)
Dim 矩形 = 控件.ClientRectangle '获取控件的工作区矩形
Dim 下面高度 = CInt(矩形.Height * 进度) '获取下面颜色块的高度
Dim 中间位置 = 矩形.Top + 矩形.Height - 下面高度 '获取中间分界线的Y坐标
Dim 上矩形 = New Rectangle(矩形.X, 矩形.Y, 矩形.Width, 矩形.Height - 下面高度)
Dim 下矩形 = New Rectangle(矩形.X, 中间位置, 矩形.Width, 下面高度)
g.FillRectangle(上面笔刷, 上矩形)
g.FillRectangle(下面笔刷, 下矩形)
'绘制文字
Dim 文字 As String = String.Format("{0:0.00}%", 进度 * 100)
g.DrawString(文字, 字体, 文字笔, 矩形, 文字格式)
End Sub
End Class
下面是Form1窗体的代码:添加一个Button1和Timer1控件,将Button1尺寸拖大点
Public Class Form1
Public g As Graphics
Public 进度条UI As New 进度条UI
Public 进度 As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
g = Button1.CreateGraphics()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
进度 += 0.01
进度条UI.绘制(Button1, g, 进度)
End Sub
End Class
Dim p As Point = Cursor.Position
Form2.Show()
Form2.Location = p
你可以这样做,设置窗体的TopMost 属性为真!
Me.TopMost = True
Form.TopMost 属性
获取或设置一个值,指示该窗体是否应显示为最顶层窗体。