نمایش نتایج 1 تا 5 از 5

نام تاپیک: فرمی که FormBorderStyle ان None است را حرکت دهیم .

  1. #1
    کاربر تازه وارد
    تاریخ عضویت
    فروردین 1401
    محل زندگی
    مشهد
    پست
    56

    Post فرمی که FormBorderStyle ان None است را حرکت دهیم .

    با سلام من خودم این مشکل رو داشتم و با این کد حل شد امیدوارم برای شما هم این مشکل رو حل کنه.
    protected override void WndProc(ref Message m)
    {
    switch(m.Msg)
    {
    case 0x84:
    base.WndProc(ref m);
    if ((int)m.Result == 0x1)
    m.Result = (IntPtr)0x2;
    return;
    }

    base.WndProc(ref m);
    }
    فایل های ضمیمه فایل های ضمیمه

  2. #2
    کاربر دائمی آواتار ROSTAM2
    تاریخ عضویت
    اسفند 1390
    محل زندگی
    فارس
    پست
    1,636

    نقل قول: فرمی که FormBorderStyle ان None است را حرکت دهیم .

    نقل قول نوشته شده توسط ghasem31372 مشاهده تاپیک
    با سلام من خودم این مشکل رو داشتم و با این کد حل شد امیدوارم برای شما هم این مشکل رو حل کنه.
    protected override void WndProc(ref Message m)
    {
    switch(m.Msg)
    {
    case 0x84:
    base.WndProc(ref m);
    if ((int)m.Result == 0x1)
    m.Result = (IntPtr)0x2;
    return;
    }

    base.WndProc(ref m);
    }
    این خوبه ولی تو یک پنجره معمولی شاید نیاز نداشته باشیم کل فرم حالت درگ داشته باشه و فقط نوار عنوانی که ایجاد کردیم رو بخوایم برای درگ کردنش استفاده کنیم برای محدوده نوار عنوان هم باید شرطی داشته باشه.
    و ی چیز دیگه شاید بخوایم پنجره رو با گرافیک خودمون طراحی کنیم پس برای تغییر ابعادش هم نیاز به شرط هست.

  3. #3
    کاربر تازه وارد آواتار god of war 313
    تاریخ عضویت
    دی 1400
    محل زندگی
    برزخ
    پست
    90

    نقل قول: فرمی که FormBorderStyle ان None است را حرکت دهیم .

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

    با تشکر از شما.

  4. #4
    کاربر دائمی آواتار ROSTAM2
    تاریخ عضویت
    اسفند 1390
    محل زندگی
    فارس
    پست
    1,636

    نقل قول: فرمی که FormBorderStyle ان None است را حرکت دهیم .

    پیدا کردم ولی تستش نکردم.


    using System;
    using System.Drawing;
    using System.Windows.Forms;


    namespace Custom_Title_Bar
    {
    public partial class MainForm : Form
    {
    private PictureBox title = new PictureBox(); // create a PictureBox
    private Label minimise = new Label(); // this doesn't even have to be a label!
    private Label maximise = new Label(); // this will simulate our this.maximise box
    private Label close = new Label(); // simulates the this.close box


    private bool drag = false; // determine if we should be moving the form
    private Point startPoint = new Point(0, 0); // also for the moving


    public MainForm()
    {
    this.FormBorderStyle = FormBorderStyle.None; // get rid of the standard title bar


    this.title.Location = this.Location; // assign the location to the form location
    this.title.Width = this.Width; // make it the same width as the form
    this.title.Height = 50; // give it a default height (you may want it taller/shorter)
    this.title.BackColor = Color.Black; // give it a default colour (or load an image)
    this.Controls.Add(this.title); // add it to the form's controls, so it gets displayed
    // if you have an image to display, you can load it, instead of assigning a bg colour
    // this.title.Image = new Bitmap(System.Environment.CurrentDirectory + "\\title.jpg");
    // if you displayed an image, alter the SizeMode to get it to display as you want it to
    // examples:
    // this.title.SizeMode = PictureBoxSizeMode.StretchImage;
    // this.title.SizeMode = PictureBoxSizeMode.CenterImage;
    // this.title.SizeMode = PictureBoxSizeMode.Zoom;
    // etc


    // you may want to use PictureBoxes and display images
    // or use buttons, there are many alternatives. This is a mere example.
    this.minimise.Text = "Minimise"; // Doesn't have to be
    this.minimise.Location = new Point(this.Location.X+5, this.Location.Y+5); // give it a default location
    this.minimise.ForeColor = Color.Red; // Give it a colour that will make it stand out
    // this is why I didn't use an image, just to keep things simple:
    this.minimise.BackColor = Color.Black; // make it the same as the PictureBox
    this.Controls.Add(this.minimise); // add it to the form's controls
    this.minimise.BringToFront(); // bring it to the front, to display it above the picture box


    this.maximise.Text = "Maximise";
    // remember to make sure it's far enough away so as not to overlap our minimise option
    this.maximise.Location = new Point(this.Location.X+60, this.Location.Y+5);
    this.maximise.ForeColor = Color.Red;
    this.maximise.BackColor = Color.Black; // remember, we want it to match the background
    this.maximise.Width = 50;
    this.Controls.Add(this.maximise); // add it to the form
    this.maximise.BringToFront();


    this.close.Text = "Close";
    this.close.Location = new Point(this.Location.X+120, this.Location.Y+5);
    this.close.ForeColor = Color.Red;
    this.close.BackColor = Color.Black;
    this.close.Width = 37; // this is just to make it fit nicely
    this.Controls.Add(this.close);
    this.close.BringToFront();


    // now we need to add some functionality. First off, let's give those labels
    // MouseHover and MouseLeave events, so they change colour
    // Since they're all going to change to the same colour, we can give them the same
    // event handler, which saves time of writing out all those extra functions
    this.minimise.MouseEnter += new EventHandler(Control_MouseEnter);
    this.maximise.MouseEnter += new EventHandler(Control_MouseEnter);
    this.close.MouseEnter += new EventHandler(Control_MouseEnter);


    // and we need to do the same for MouseLeave events, to change it back
    this.minimise.MouseLeave += new EventHandler(Control_MouseLeave);
    this.maximise.MouseLeave += new EventHandler(Control_MouseLeave);
    this.close.MouseLeave += new EventHandler(Control_MouseLeave);


    // and lastly, for these controls, we need to add some functionality
    this.minimise.MouseClick += new MouseEventHandler(Control_MouseClick);
    this.maximise.MouseClick += new MouseEventHandler(Control_MouseClick);
    this.close.MouseClick += new MouseEventHandler(Control_MouseClick);


    // finally, wouldn't it be nice to get some moveability on this control?
    this.title.MouseDown += new MouseEventHandler(Title_MouseDown);
    this.title.MouseUp += new MouseEventHandler(Title_MouseUp);
    this.title.MouseMove += new MouseEventHandler(Title_MouseMove);
    }


    private void Control_MouseEnter(object sender, EventArgs e)
    {
    if (sender.Equals(this.close))
    this.close.ForeColor = Color.White;
    else if (sender.Equals(this.maximise))
    this.maximise.ForeColor = Color.White;
    else // it's the minimise label
    this.minimise.ForeColor = Color.White;
    }


    private void Control_MouseLeave(object sender, EventArgs e)
    { // return them to their default colours
    if (sender.Equals(this.close))
    this.close.ForeColor = Color.Red;
    else if (sender.Equals(this.maximise))
    this.maximise.ForeColor = Color.Red;
    else // it's the minimise label
    this.minimise.ForeColor = Color.Red;
    }


    private void Control_MouseClick(object sender, MouseEventArgs e)
    {
    if (sender.Equals(this.close))
    this.Close(); // close the form
    else if (sender.Equals(this.maximise))
    { // maximise is more interesting. We need to give it different functionality,
    // depending on the window state (Maximise/Restore)
    if (this.maximise.Text == "Maximise")
    {
    this.WindowState = FormWindowState.Maximized; // maximise the form
    this.maximise.Text = "Restore"; // change the text
    this.title.Width = this.Width; // stretch the title bar
    }
    else // we need to restore
    {
    this.WindowState = FormWindowState.Normal;
    this.maximise.Text = "Maximise";
    }
    }
    else // it's the minimise label
    this.WindowState = FormWindowState.Minimized; // minimise the form
    }


    void Title_MouseUp(object sender, MouseEventArgs e)
    {
    this.drag = false;
    }


    void Title_MouseDown(object sender, MouseEventArgs e)
    {
    this.startPoint = e.Location;
    this.drag = true;
    }


    void Title_MouseMove(object sender, MouseEventArgs e)
    {
    if (this.drag)
    { // if we should be dragging it, we need to figure out some movement
    Point p1 = new Point(e.X, e.Y);
    Point p2 = this.PointToScreen(p1);
    Point p3 = new Point(p2.X - this.startPoint.X,
    p2.Y - this.startPoint.Y);
    this.Location = p3;
    }
    }
    } // end of the class
    } // end of the namespace


    https://stackoverflow.com/questions/...stom-title-bar

  5. #5
    کاربر دائمی آواتار ROSTAM2
    تاریخ عضویت
    اسفند 1390
    محل زندگی
    فارس
    پست
    1,636

    نقل قول: فرمی که FormBorderStyle ان None است را حرکت دهیم .

    فقط کافیه ی پنل بعنوان نوار عنوان اضافه شه و رویدادهای مربوط به درگ هم به اون اضافه بشه:

    Form1.zip

    Untitled.png


    public partial class Form1 : Form
    {
    private bool drag = false; // determine if we should be moving the form
    private Point startPoint = new Point(0, 0); // also for the moving
    public Form1()
    {
    InitializeComponent();
    }

    void Title_MouseUp(object sender, MouseEventArgs e)
    {
    this.drag = false;
    }


    void Title_MouseDown(object sender, MouseEventArgs e)
    {
    this.startPoint = e.Location;
    this.drag = true;
    }


    void Title_MouseMove(object sender, MouseEventArgs e)
    {
    if (this.drag)
    { // if we should be dragging it, we need to figure out some movement
    Point p1 = new Point(e.X, e.Y);
    Point p2 = this.PointToScreen(p1);
    Point p3 = new Point(p2.X - this.startPoint.X,
    p2.Y - this.startPoint.Y);
    this.Location = p3;
    }
    }


    private void Title_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    g.Clear(title.BackColor);
    g.DrawString("Title", title.Font, Brushes.White, 2, 2);
    }



    }

تاپیک های مشابه

  1. سوال: چگونه فرمی که FormBorderStyle ان None است را حرکت دهیم .
    نوشته شده توسط Jaxon_hacker_black در بخش C#‎‎
    پاسخ: 3
    آخرین پست: شنبه 19 بهمن 1392, 13:00 عصر
  2. مشکل در FormBorderStyle
    نوشته شده توسط MaHyaR.DrAcOulA در بخش C#‎‎
    پاسخ: 3
    آخرین پست: جمعه 20 آبان 1390, 21:48 عصر
  3. سوال: حرکت دادن فرم با خصوصیت formborderstyle=none
    نوشته شده توسط hamidhws در بخش VB.NET
    پاسخ: 2
    آخرین پست: یک شنبه 08 آذر 1388, 18:13 عصر
  4. Minimize کردن فرمی با FormBorderStyle = None
    نوشته شده توسط Open-Source در بخش C#‎‎
    پاسخ: 6
    آخرین پست: چهارشنبه 08 مهر 1388, 07:32 صبح
  5. FormBorderStyle
    نوشته شده توسط Mahdi_20 در بخش C#‎‎
    پاسخ: 2
    آخرین پست: چهارشنبه 02 شهریور 1384, 11:32 صبح

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •