PDA

View Full Version : سوال: خارج نشدن فرم از صفحه مانیتور



sadaf_
دوشنبه 24 بهمن 1390, 12:49 عصر
چطوری می شه کاری کرد که فرم از صفحه مانیتور بیرون نره
وقتی بالای نوار ابزار فرم هم drag می شه و به این طرف و آن طرف کشیده می شه هم این اتفاق نیافته
ممنون

saeedsos007
دوشنبه 24 بهمن 1390, 16:37 عصر
روی داد move فرم را به این حالت قرار بده
int x=100;
int y=100;
int bottom = Screen.PrimaryScreen.Bounds.Height;
int right = Screen.PrimaryScreen.Bounds.Width;
private void search_factor_2_Move(object sender, EventArgs e)
{
if (this.Location.X < 1)
{
x = 1;
this.Location = new Point(x, this.Location.Y);
}
if (this.Location.Y < 1)
{
y = 1;
this.Location = new Point(this.Location.X,y);
}
if (this.Location.X + this.Width > right)
{
x = this.Location.X;
x--;
this.Location = new Point(x--, this.Location.Y);
}
if (this.Location.Y + this.Height > bottom)
{
y = this.Location.Y;
y--;
this.Location = new Point(this.Location.X,y);
}

}

sadaf_
دوشنبه 24 بهمن 1390, 17:07 عصر
عالی بود جواب داد
فقط یه مشکل کوچک وجود داره
وقتی با موس drag می کنی و از مانیتور بره بیرون فرم بال بال می زنه
یعنی همش بر می گرده سر جاش اینو کاری نمی شه کرد
یعنی بشه کاری کرد که فرم از مانیتور خارج نشه که همش بخواد بره سر جاش
ممنون

saeedsos007
دوشنبه 24 بهمن 1390, 17:21 عصر
ببخشید اینو دیگه نمیدونم
فکر کنم دیگه کارای گرافیکی میشه

mrbm_2007
سه شنبه 25 بهمن 1390, 20:29 عصر
عالی بود جواب داد
فقط یه مشکل کوچک وجود داره
وقتی با موس drag می کنی و از مانیتور بره بیرون فرم بال بال می زنه
یعنی همش بر می گرده سر جاش اینو کاری نمی شه کرد
یعنی بشه کاری کرد که فرم از مانیتور خارج نشه که همش بخواد بره سر جاش
ممنون

int bottom = Screen.PrimaryScreen.Bounds.Height;
int right = Screen.PrimaryScreen.Bounds.Width;
private void search_factor_2_Move(object sender, EventArgs e)
{
if (Location.X < 1)
{
Location = new Point(1, Location.Y);
SendKeys.Send("{ENTER}");
}
if (Location.Y < 1)
{
Location = new Point(Location.X, 1);
SendKeys.Send("{ENTER}");
}
if (Location.X + Width > right)
{
Location = new Point(right - Width, Location.Y);
SendKeys.Send("{ENTER}");
}
if (Location.Y + Height > bottom)
{
Location = new Point(Location.X, bottom - Height);
SendKeys.Send("{ENTER}");
}
}

sadaf_
چهارشنبه 26 بهمن 1390, 10:30 صبح
آیا جایگزین مناسبی عیر از این دستور هست؟

SendKeys.Send("{ENTER}");

mahan.2002
چهارشنبه 26 بهمن 1390, 11:01 صبح
فکر میکنم راه حل خوبی دادن ایشون
فقط یه نکته هست که فرم وقتی به کنار ها میرسه حرکت نمیکنه. و دوباره باید گرفته بشه و حرکت داد.

sadaf_
چهارشنبه 26 بهمن 1390, 11:13 صبح
آخه من در event از enter استفاده می کنم اگر می شه یه جایگزین دیگه بهم بدید
ممنون

nunegandom
چهارشنبه 26 بهمن 1390, 11:25 صبح
سلام



int bottom = Screen.PrimaryScreen.Bounds.Height;
int right = Screen.PrimaryScreen.Bounds.Width;
private void search_factor_2_Move(object sender, EventArgs e)
{
if (Location.X < 1)
{
Location = new Point(1, Location.Y);
e = EventArgs.Empty;
}
if (Location.Y < 1)
{
Location = new Point(Location.X, 1);
e = EventArgs.Empty;
}
if (Location.X + Width > right)
{
Location = new Point(right - Width, Location.Y);
e = EventArgs.Empty;
}
if (Location.Y + Height > bottom)
{
Location = new Point(Location.X, bottom - Height);
e = EventArgs.Empty;
}
}

mahan.2002
چهارشنبه 26 بهمن 1390, 11:28 صبح
شما از این استفاده کن فکر می کنم دیگه گیرم نمی کنه... البته تشکرش از دوستمون باید بکنید که این کد رو نوشتن ..


int bottom = Screen.PrimaryScreen.Bounds.Height;
int right = Screen.PrimaryScreen.Bounds.Width;

private void Form1_Move(object sender, EventArgs e)
{

if (Location.X < 1)
{
Location = new Point(1, Location.Y);
SendKeys.Send("{SPACE}");
}
if (Location.Y < 1)
{
Location = new Point(Location.X, 1);
SendKeys.Send("{SPACE}");
}
if (Location.X + Width > right)
{
Location = new Point(right - Width, Location.Y);
SendKeys.Send("{SPACE}");
}
if (Location.Y + Height > bottom)
{
Location = new Point(Location.X, bottom - Height);
SendKeys.Send("{SPACE}");
}



}

sadaf_
جمعه 28 بهمن 1390, 13:01 عصر
int bottom = Screen.PrimaryScreen.Bounds.Height;
int right = Screen.PrimaryScreen.Bounds.Width;
private void search_factor_2_Move(object sender, EventArgs e)
{
if (Location.X < 1)
{
Location = new Point(1, Location.Y);
e = EventArgs.Empty;
}
if (Location.Y < 1)
{
Location = new Point(Location.X, 1);
e = EventArgs.Empty;
}
if (Location.X + Width > right)
{
Location = new Point(right - Width, Location.Y);
e = EventArgs.Empty;
}
if (Location.Y + Height > bottom)
{
Location = new Point(Location.X, bottom - Height);
e = EventArgs.Empty;
}
}

با تشکر
این دستور چواب داد
اما اگر دقت کنید باز هم یه مقدار فرم حالت طبیعی خودش رو از دست می ده
آیا باز هم جایی برای بهینه تر شدن داره؟
ممنون