السلام عليكم
ازاى اغير وظيفة Close[X] & Minimize Buttons فاى Form ?
السلام عليكم
ازاى اغير وظيفة Close[X] & Minimize Buttons فاى Form ?
EXP كتب:السلام عليكمازاى اغير وظيفة Close[X] & Minimize Buttons فاى Form ?
إستخدم حدث إغلاق الفورم :
FormClosing
وأكتب الكود الذي تريده وفي آخر سطر قم بإلغاء أمر إغلاق الفورم:
e.Cancel=true;
..
protected override void WndProc(ref Message m)
{
const int WM_SysCommand = 0x0112;
// System Menu Command Values
const int SC_Size = 0xF000;
const int SC_Move = 0xF010;
const int SC_Minimize = 0xF020;
const int SC_Maximize = 0xF030;
const int SC_Close = 0xF060; // Closes the window.
const int SC_Restore = 0xF120;
if (m.Msg == WM_SysCommand)
{
switch (m.WParam.ToInt32())
{
case SC_Close:
MessageBox.Show("Close");
return;
case SC_Minimize:
MessageBox.Show("Minimize");
return;
case SC_Maximize:
MessageBox.Show("Maximize");
return;
case SC_Move:
MessageBox.Show("Move");
return;
case SC_Size:
MessageBox.Show("Size");
return;
case SC_Restore:
MessageBox.Show("Restore");
return;
default:
break;
}
}
base.WndProc(ref m);
}تم تعديل هذه المشاركة بواسطة Moudey في 18 يونيو 2008 في 02:16
السلام عليكم ورحمة الله وبركاته
استاذ مودي ممكن توضح ازاي نستخدم هذه function
/*
TestSystemCommand.cs
Compile : CSC /target:winexe /debug TestSystemCommand.cs
*/
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TestSystemCommand
{
public class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.Run(new frmTest());
}
}
public class frmTest : Form
{
public frmTest()
{
this.Size = new Size(500,400);
this.Text = "Test System Command";
this.StartPosition = FormStartPosition.CenterScreen;
}
/// <summary>
/// Processes Windows messages.
/// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc.aspx"/>
/// </summary>
protected override void WndProc(ref Message m)
{
// Constant value was found in the "windows.h" header file.
// A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or
// when the user chooses the maximize button, minimize button, restore button, or close button.
const int WM_SysCommand = 0x0112;
// System Menu Command Values
const int SC_Size = 0xF000; // Sizes the window.
const int SC_Move = 0xF010; // Moves the window.
const int SC_Minimize = 0xF020; // Minimizes the window.
const int SC_Maximize = 0xF030; // Maximizes the window.
const int SC_Close = 0xF060; // Closes the window.
const int SC_Restore = 0xF120; // Restores the window to its normal position and size.
// Listen for operating system messages.
if (m.Msg == WM_SysCommand)
{
switch (m.WParam.ToInt32())
{
case SC_Close:
if (MessageBox.Show("Are you sure you want to close the app?", this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
Application.Exit();
}
return;
case SC_Minimize:
MessageBox.Show("Minimize");
break;
case SC_Maximize:
MessageBox.Show("Maximize");
break;
case SC_Move:
MessageBox.Show("Move");
break;
case SC_Size:
MessageBox.Show("Size");
break;
case SC_Restore:
MessageBox.Show("Restore");
break;
default:
break;
}
}
base.WndProc(ref m);
}
}
}شكرا لك اخى Moudey
هل بالطريقة دى بتتغير كل وظائف الWindow Menu ?
لو اة ازاى اغير وظيفة Close بس مثلا
و اللى مش فهمو من الكود هوة لية بينادى على base.WndProc
تم تعديل هذه المشاركة بواسطة EXP في 19 يونيو 2008 في 01:27
لأنة الاجراء المسؤل عن معالجة رسائل النافذة الحالية.
اقتباسهل بالطريقة دى بتتغير كل وظائف الWindow Menu ?
يمكنك التحكم في النافذة بالكامل من خلال هذا الاجراء ولكن يجب عليك ان تلم بـ Windows messages
يمكن مراجعة الروابط التالي للتوضيح اكثر
اقتباسلو اة ازاى اغير وظيفة Close بس مثلا
عزيزي اعتقد انك لم تقم بعمل Compile للشيفرة الموجودة بالاعلي.
او نسخ اجراء WndProc في جسم شيفرة الفورم.
لقد قمت بالتحكم في جميع اوامر القائمة ما عليك سوي وضع الاجراء الذي ترغب في تنفيذة.
السلام عليكم
يمكنك تطبيق ما ذكره الأخ Moudey
أو يمكنك فعل ما يلي:
التقاط حدث إغلاق النافذة من خلال الحدث (Form_Closing) وبعد ذلك يمكنك كتابة الكود الذي تشاء كما يمكنك إلغاء حدث الإغلاق.
التقاط حدث تغير حجم النافذة من خلال الحدث (SizeChanged) و بعد ذلك عليك اختبار حالة (WindowState) فإذا كانت
(Minimized) فالمستخدم قد ضغط على زر التصغير (-) و أيضاً يمكنك إلغاء هذا الحدث والتعديل عليه.
LORD COVER
GOOD BYTE
مؤسس شبكة مواقع إجابتي أول شبكة مواقع عربية للأسئلة والأجوبة
شكرا Moudey
مكنتش واخد بالى من Return & break