چطوری میتونم یه حالت چسبنده به فرم بدم
مثل winamp که مثل اهن ربا به taskbar میچسبه
چطوری میتونم یه حالت چسبنده به فرم بدم
مثل winamp که مثل اهن ربا به taskbar میچسبه
ابعاد taskbar را چگونه میشه بدست اورد تا فرم را دقیقا بالای taskbar قرار داد
هر دو سوال در مورد location فرم هست :
منظور از این سوال که من خیلی وقته می خواهم بپرسم و هر دفعه یادم میرفته اینه که
location فرم رو جوری Set کنیم که وقتی به یک کادری در نزدیکی قرار می گیره از یک مقداری کمتر با اون کادر کناری فاصله کمتر پیدا نکنه و مثلا اگه کمتر از 5 پیکسل شد بچسبه به کادر کناری ؟
منظور از این سوال که سرچ من هم بود اینه که :
آیا راهی هست که بتونیم فرم رو با فاصله ی 0 از taskbar لود کنیم .یا اصولا مقدار ضخامت نوار وظیفه را پیدا کنیم ؟
this.Location = new Point(0, SystemInformation.PrimaryMonitorMaximizedWindowSiz e.Height - this.Size.Height - 25);
اون عدد 25 رو همینجوری نوشتم .
توی رزولوشن های مختلف مقدار ضخامت taskbar فرق میکنه ...
سلام
یک نکته:برای بدست آوردن ضخامت و نیز مکان تسک بار از تابع SHAppBarMessage از کتابخونه SHELL32.dll باید استفاده کنی
حالا کار هایی که می گم به ترتیب بکن یک فرم آهن ربایی باحال خواهی داشت:
ابتدا این رو اضافه کن:
using System.Runtime.InteropServices;
این توابع و متغییر ها رو به اول کدت اضافه کن:
int X=0, Y = 0;
[DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}
enum ABEdge : int
{
ABE_LEFT = 0,
ABE_TOP,
ABE_RIGHT,
ABE_BOTTOM
}
private void GetTaskBarInfo(out int height,out string Location)
{
APPBARDATA abd = new APPBARDATA();
height = 0;
Location = null;
uint ret = SHAppBarMessage(5, ref abd);
switch (abd.uEdge)
{
case (int)ABEdge.ABE_BOTTOM:
height = abd.rc.bottom - abd.rc.top;
Location = "B";
break;
case (int)ABEdge.ABE_TOP:
height = abd.rc.bottom;
Location = "T";
break;
case (int)ABEdge.ABE_LEFT:
height = abd.rc.right - abd.rc.left;
Location = "L";
break;
case (int)ABEdge.ABE_RIGHT:
height = abd.rc.right - abd.rc.left;
Location = "R";
break;
}
}
private void ScreenBounds(out int Width, out int Height)
{
int X = 0;
int y = 0;
int H = 0;
string Location = null;
GetTaskBarInfo(out H,out Location);
Screen sc = Screen.PrimaryScreen;
X = sc.Bounds.Width;
y = sc.Bounds.Height;
switch (Location)
{
case "T":
case "B":
y -= H;
break;
case "L":
case "R":
X -= H;
break;
}
Width = X;
Height = y;
}
حالا تو ایونت لود فرمت بنویس:
ScreenBounds(out X,out Y);
حالا تو ایونت LocationChangedاز فرمت بنویس:
if (this.Location.X < 100 && this.Location.Y>50)
{
this.Location = new Point(0, this.Location.Y);
return;
}
if ((this.Location.X + this.Width) > X - 100 && (this.Location.Y + this.Height) < Y - 100)
{
this.Location = new Point(X - this.Width, this.Location.Y);
return;
}
if (this.Location.Y < 50 && this.Location.X>100)
{
this.Location = new Point(this.Location.X,0);
return;
}
if ((this.Location.Y + this.Height) > Y - 100 && (this.Location.X + this.Width) < X - 100)
{
this.Location = new Point(this.Location.X, Y - this.Height);
return;
}
if (this.Location.X < 100 && this.Location.Y < 50)
{
this.Location = new Point(0, 0);
return;
}
if ((this.Location.Y + this.Height) > Y - 100 && (this.Location.X + this.Width) > X - 100)
{
this.Location = new Point(X - this.Width, Y - this.Height);
return;
}
حالا به محض اینکه نزدیک هر کدوم از گوشه های بالا سمت چپ و پایین سمت راست کنی بهش می چسبه (دو گوش دیگه رو خودت بساز )
اگر هم به 50 پیکسلی بالای صفحه نمایش و یا بلای تسک بار نزدیکش کنی می چسبه به اون
برای لبه راست و چپ نیاز به 100 پیکسلیشون نزدیکشون کنی