1.在mouse事件中實(shí)現(xiàn)
創(chuàng)新互聯(lián)公司2013年至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站制作、網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元寶清做網(wǎng)站,已為上家服務(wù),為寶清各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
2.調(diào)用windows API
實(shí)現(xiàn)方式為:
1.在mouse事件中實(shí)現(xiàn)
[csharp] view plain copy
Point mouseOff;//鼠標(biāo)移動位置變量
bool leftFlag;//標(biāo)簽是否為左鍵
private void groupControl1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//釋放鼠標(biāo)后標(biāo)注為false;
}
}
private void groupControl1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //設(shè)置移動后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點(diǎn)擊左鍵按下時(shí)標(biāo)注為true;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點(diǎn)擊左鍵按下時(shí)標(biāo)注為true;
}
}
2.調(diào)用windows API
調(diào)用前需要添加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(); //釋放鼠標(biāo)捕捉
//發(fā)送左鍵點(diǎn)擊的消息至該窗體(標(biāo)題欄)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
花了二十分鐘給你寫了代碼,已測試。建議學(xué)習(xí)并使用System.Drawing繪制。
主要是掌握Graphics.FillRectangle和DrawString的使用。
Imports?System.Drawing
Public?Class?進(jìn)度條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
'''?繪制指定進(jìn)度的圖像。
'''?當(dāng)進(jìn)度變化時(shí)調(diào)用一次本方法,建議將創(chuàng)建的Graphics對象保存到變量而不要重復(fù)創(chuàng)建。。
'''?/summary
'''?param?name="控件"繪制到此控件的工作區(qū)/param
'''?param?name="g"繪制到控件的Graphics對象,例如?Button1.CreateGraphics()/param
'''?param?name="進(jìn)度"進(jìn)度百分比實(shí)數(shù),57%?=?0.57/param
Public?Sub?繪制(ByRef?控件?As?Control,?ByRef?g?As?Graphics,?ByVal?進(jìn)度?As?Double)
Dim?矩形?=?控件.ClientRectangle?'獲取控件的工作區(qū)矩形
Dim?下面高度?=?CInt(矩形.Height?*?進(jìn)度)?'獲取下面顏色塊的高度
Dim?中間位置?=?矩形.Top?+?矩形.Height?-?下面高度?'獲取中間分界線的Y坐標(biāo)
Dim?上矩形?=?New?Rectangle(矩形.X,?矩形.Y,?矩形.Width,?矩形.Height?-?下面高度)
Dim?下矩形?=?New?Rectangle(矩形.X,?中間位置,?矩形.Width,?下面高度)
g.FillRectangle(上面筆刷,?上矩形)
g.FillRectangle(下面筆刷,?下矩形)
'繪制文字
Dim?文字?As?String?=?String.Format("{0:0.00}%",?進(jìn)度?*?100)
g.DrawString(文字,?字體,?文字筆,?矩形,?文字格式)
End?Sub
End?Class
下面是Form1窗體的代碼:添加一個Button1和Timer1控件,將Button1尺寸拖大點(diǎn)
Public?Class?Form1
Public?g?As?Graphics
Public?進(jìn)度條UI?As?New?進(jìn)度條UI
Public?進(jìn)度?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
進(jìn)度?+=?0.01
進(jìn)度條UI.繪制(Button1,?g,?進(jìn)度)
End?Sub
End?Class
Dim p As Point = Cursor.Position
Form2.Show()
Form2.Location = p
你可以這樣做,設(shè)置窗體的TopMost 屬性為真!
Me.TopMost = True
Form.TopMost 屬性
獲取或設(shè)置一個值,指示該窗體是否應(yīng)顯示為最頂層窗體。