1、拖動出來以后,需要創(chuàng)建一個大小合適的窗口,作為工具欄新的停靠容器,這個窗口可以這樣設(shè)置:

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),夏縣企業(yè)網(wǎng)站建設(shè),夏縣品牌網(wǎng)站建設(shè),網(wǎng)站定制,夏縣網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,夏縣網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
ShowIcon = false;
ShowInTaskbar = false;
TopMost = true;
2、浮動工具欄可以擴展自.Net
Framework提供的ToolStrip,它被拖動都某個位置,松開鼠標(biāo)左鍵時,會觸發(fā)EndDarg事件,在這個事件中,我們將其從原來的停靠容器中移除,同時根據(jù)鼠標(biāo)左鍵松開時,在鼠標(biāo)所在位置上創(chuàng)建一個窗口,作為工具欄的新容器。
這個就是基本的思路了,下面是浮動工具欄FloatToolstrip 具體的實現(xiàn)代碼:
[csharp] view plain copy print?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace FloatToolStripDemo
{
public partial class FloatToolstrip : ToolStrip
{
private ToolStripPanel tsPanel;
public FloatToolstrip()
{
InitializeComponent();
this.EndDrag += new EventHandler(MyToolStrip_EndDrag);
this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged);
}
private ToolStripFloatWindow floatForm;
public ToolStripFloatWindow FloatForm
{
get { return floatForm; }
set
{
floatForm = value;
if (floatForm != null)
{
floatForm.LocationChanged += new EventHandler(floatForm_LocationChanged);
floatForm.FormClosing += new FormClosingEventHandler(floatForm_FormClosing);
}
}
}
void floatForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
private void floatForm_LocationChanged(object sender, EventArgs e)
{
//當(dāng)floatwindws的位置移動到toolstrippanel中時,將this放置到 toolstripPanel上
if (this.floatForm == null)
{
return;
}
else
{
if (floatForm.HasCreated)
{
Point currentPt = new Point(floatForm.Location.X, floatForm.Location.Y);
Point minPt = this.tsPanel.PointToScreen(tsPanel.Location);
Point maxPt;
if (this.tsPanel.Height = 20)
{
maxPt = new Point(minPt.X + this.tsPanel.Width, minPt.Y + 20);
}
else
{
maxPt = new Point(minPt.X + this.tsPanel.Width, minPt.Y + this.tsPanel.Height);
}
if ((currentPt.X minPt.X) (currentPt.X maxPt.X) (currentPt.Y minPt.Y - 25) (currentPt.Y maxPt.Y - 25))
{
this.floatForm.Controls.Remove(this);
this.tsPanel.SuspendLayout();
this.tsPanel.Controls.Add(this);
this.Location = this.tsPanel.PointToClient(currentPt);
this.tsPanel.ResumeLayout();
this.floatForm.Dispose();
this.floatForm = null;
}
}
}
}
public bool isFloating
{
get
{
return (floatForm != null);
}
}
public ToolStripPanel ToolStripPanel
{
get
{
return this.tsPanel;
}
set
{
this.tsPanel = value;
}
}
private void MyToolStrip_EndDrag(object sender, EventArgs e)
{
//判斷移除時
if (this.tsPanel == null)
{
MessageBox.Show("請先設(shè)置ToolStripPanel屬性");
return;
}
Point dockPoint = Cursor.Position;
int openX, openY;
openX = dockPoint.X;
openY = dockPoint.Y;
Point clientPt = this.tsPanel.Parent.PointToClient(dockPoint);
if (clientPt.Y tsPanel.Height)
{
ToolStripFloatWindow tsfw = new ToolStripFloatWindow();
this.tsPanel.Controls.Remove(this);
tsfw.Controls.Add(this);
this.Left = 0;
this.Top = 0;
this.FloatForm = tsfw;
Point newLoc = new Point(openX, openY);
tsfw.Show();
tsfw.Location = newLoc;
tsfw.SetBounds(newLoc.X, newLoc.Y, this.ClientSize.Width, this.ClientSize.Height+25);
}
}
private void MyToolStrip_SizeChanged(object sender, EventArgs e)
{
if (this.isFloating)
{
this.floatForm.Width = this.ClientSize.Width;
}
}
}
}
動態(tài)創(chuàng)建的作為浮動工具欄臨時容器的窗口,需要加入一些處理技巧,以免發(fā)生在創(chuàng)建該窗口的工作尚未結(jié)束時,Dispose了這個窗口,這種情況發(fā)生在快速拖動工具欄時,觸發(fā)了EndDrag事件,導(dǎo)致去創(chuàng)建臨時窗口作為工具欄新的容器,而這時又將工具欄拖回原停靠容器中,會導(dǎo)致Dispose還沒有創(chuàng)建完畢的臨時窗口,發(fā)生異常!
可以做一個窗體,該窗體中放入你需要的菜單。
這個窗體幾個特殊設(shè)置:
1。TOPmost設(shè)置為TRUE
2。Formborderstyle設(shè)置為none
3。showintaskbar設(shè)置為False
4。size設(shè)置為你的菜單大小
用的時候new一下就有啦!
這樣就相當(dāng)于懸浮窗體了,細(xì)節(jié)自己研究吧!^_^
1、禁止對話框中的關(guān)閉按鈕有二種方法。 第一種方法 ,用ModiftMenu()涵數(shù)來實現(xiàn): CMenu* pMenu = this-GetSystemMenu(FALSE); pMenu-ModifyMenu(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED );第二種方法 ,用EnableMenuItem()涵數(shù)來實現(xiàn): CMenu* pMenu = this-GetSystemMenu(FALSE); pMenu-EnableMenuItem( SC_CLOSE, MF_BYCOMMAND|MF_GRAYED); 2、禁止浮動工具條上的系統(tǒng)菜單。 新建一個CToolBar的派生類CxxToolBar,在新類中的左鍵雙擊(CxxToolBar::OnLButtonDblClk(...))和左鍵單擊(CxxToolBar:: OnLButtonDown(...))涵數(shù)中分別加入下面代碼既可: if (IsFloating()) //工具條正在浮動狀態(tài)中{CWnd* pMiniFrame; CWnd* pDockBar; pDockBar = GetParent(); pMiniFrame = pDockBar-GetParent(); //去除其上系統(tǒng)菜單 pMiniFrame-ModifyStyle(WS_SYSMENU, NULL); //重繪工具條 pMiniFrame-ShowWindow(SW_HIDE); pMiniFrame-ShowWindow(SW_SHOW);}3、禁止窗口最大化按鈕
1、首先點擊屏幕左上角的蘋果標(biāo)志。
2、選擇“系統(tǒng)偏好設(shè)置”。
3、打開后,選擇“dock”,注意,10.14以上版本的Mac系統(tǒng)中這里叫“程序塢”。
4、取消勾選自動顯示和隱藏Dock。
5、取消之后,下方就會出現(xiàn)工具條了。
6、最后點擊左上角的紅色叉號,關(guān)閉系統(tǒng)偏好設(shè)置即可。
創(chuàng)建工具欄很簡單,直接使用CommandBars集合的Add方法,除了需要指定Name屬性之外,可以接受其它所有的默認(rèn)屬性值。可以通過Position屬性指定工具欄顯示的位置。
Position屬性的值由msoBarPosition常數(shù)指定。
msoBarLeft: 0,工具欄顯示在工作表左邊
msoBarTop: 1,工具欄顯示在工作表上邊
msoBarRight: 2,工具欄顯示在工作表右邊
msoBarBottom: 3,工具欄顯示在工作表下邊
msoBarFloating: 4,工具欄浮動顯示
msoBarMenuBar: 5,這個常數(shù)表示創(chuàng)建菜單欄,不用于創(chuàng)建工具欄
msoBarPopup: 6,這個常數(shù)表示創(chuàng)建彈出菜單
本文題目:浮動工具條vb.net 可以浮動字跡的工具
網(wǎng)頁鏈接:http://www.yijiale78.com/article44/dooshhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、建站公司、網(wǎng)站制作、虛擬主機、App設(shè)計、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)