استدعاء method تقوم باضافة ظل للفورم - Rabeea Qbaha - 03-10-19
السلام عليكم
لدي كود يقوم باضافة ظل للفورم ، حاولت ان احولة ل class اقوم باستدعائة عند الحاجة
لكن طهر لي مشاكل.
احتاج لجعل هذا الكود في class لاستدعائة عند الحاجة
الكود :
PHP كود :
/***********************************************************************/ // SHADOW FORM START /***********************************************************************/
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] private static extern IntPtr CreateRoundRectRgn ( int nLeftRect, // x-coordinate of upper-left corner int nTopRect, // y-coordinate of upper-left corner int nRightRect, // x-coordinate of lower-right corner int nBottomRect, // y-coordinate of lower-right corner int nWidthEllipse, // height of ellipse int nHeightEllipse // width of ellipse );
[DllImport("dwmapi.dll")] public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
[DllImport("dwmapi.dll")] public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")] public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
private bool m_aeroEnabled; // variables for box shadow private const int CS_DROPSHADOW = 0x00020000; private const int WM_NCPAINT = 0x0085; private const int WM_ACTIVATEAPP = 0x001C;
public struct MARGINS // struct for box shadow { public int leftWidth; public int rightWidth; public int topHeight; public int bottomHeight; }
private const int WM_NCHITTEST = 0x84; // variables for dragging the form private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2;
protected override CreateParams CreateParams { get { m_aeroEnabled = CheckAeroEnabled();
CreateParams cp = base.CreateParams; if (!m_aeroEnabled) cp.ClassStyle |= CS_DROPSHADOW;
return cp; } }
private bool CheckAeroEnabled() { if (Environment.OSVersion.Version.Major >= 6) { int enabled = 0; DwmIsCompositionEnabled(ref enabled); return (enabled == 1) ? true : false; } return false; }
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_NCPAINT: // box shadow if (m_aeroEnabled) { var v = 2; DwmSetWindowAttribute(this.Handle, 2, ref v, 4); MARGINS margins = new MARGINS() { bottomHeight = 1, leftWidth = 1, rightWidth = 1, topHeight = 1 }; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
} break; default: break; } base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) // drag the form m.Result = (IntPtr)HTCAPTION;
} /***********************************************************************/ // SHADOW FORM END /***********************************************************************/
RE: استدعاء method تقوم باضافة ظل للفورم - asemshahen5 - 04-10-19
هذا مشروع قريب مما تريد :
winform.DropShadow
RE: استدعاء method تقوم باضافة ظل للفورم - elgokr - 08-10-19
وعليكم السلام ورحمة الله وبركاته
مرحباً اخى Rabeea Qbaha
تفضل يمكنك استخدام هذا الكلاس
كود :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
class Class1 : Button
{
/***********************************************************************/
// SHADOW FORM START
/***********************************************************************/
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
[DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
private bool m_aeroEnabled; // variables for box shadow
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVATEAPP = 0x001C;
public struct MARGINS // struct for box shadow
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
private const int WM_NCHITTEST = 0x84; // variables for dragging the form
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override CreateParams CreateParams
{
get
{
m_aeroEnabled = CheckAeroEnabled();
CreateParams cp = base.CreateParams;
if (!m_aeroEnabled)
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0;
DwmIsCompositionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT: // box shadow
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 1,
rightWidth = 1,
topHeight = 1
};
DwmExtendFrameIntoClientArea(this.Handle, ref margins);
}
break;
default:
break;
}
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) // drag the form
m.Result = (IntPtr)HTCAPTION;
}
/***********************************************************************/
// SHADOW FORM END
/***********************************************************************/
}
}
تحياتى لك
وتمنياتى لك التوفيق
RE: استدعاء method تقوم باضافة ظل للفورم - asemshahen5 - 08-10-19
لقد صنعت زر متحرك ياخذ تكبير بدبل كليك و تستطيع تحريكه وقت التشغيل دون ظل .
RE: استدعاء method تقوم باضافة ظل للفورم - elgokr - 08-10-19
تاكد من استدعاء الكلا Test كما هو لديك من اسم الكلاس
حتى يتم التعرف عليه فى الفورم الذى لديك
أو ارفق مشروع يحتوى على عدد 2 فورم
الاول يحتوى على الكود الاعتيادي الذى سبق وتقوم باستخدامه
والثاني بالطريقة خاصة الكلاس للاطلا عليه وتعديل المشروع واعادة ارفاقه لك
تحياتى لك
وتمنياتى لك التوفيق
RE: استدعاء method تقوم باضافة ظل للفورم - asemshahen5 - 08-10-19
بالكلاس انت معرف الكلاس كاداة زر : class Class1 : Button
تفضل هذا المثال :
RE: استدعاء method تقوم باضافة ظل للفورم - elgokr - 08-10-19
تم مراجعة المرفق ولا يوجد به اى مشكلة
يبدو ان هناك سوء فى بداية الموضوع حيث انه يتحدث صاحب الموضوع
كون الكود يقوم بعمل تظليل للشئ المحدد له ولكن الامر ليس هكذا
كل الامر هو تمكين حركة الاداء وكل ما فعلته هو تحويل الكود
للعمل كا كلاس على اداء طبقاً لما يقوم بتحديده من خلال تغيير هذه الجملة
قد يكون صاحب الموضوع وضع كود بدلاً من كود اخر عند كتابة الموضوع
او هناك خطاء ماء لم انتبه له لعل عند تواجد صاحب الموضوع وضع صورة لشكل الفورم عند تنفيذ الكود
مع ارفاق سورس للشاشة مع الكود لاتمام تحويله الى كلاس
والله اعلم قد اكون انا سهوت عن شئ لم انتبه اليه الى هذه اللحظة
تحياتى لك
وتمنياتى لك التوفيق
RE: استدعاء method تقوم باضافة ظل للفورم - asemshahen5 - 08-10-19
وجدت بعد البحث هذا المثال في GetHup به كل شيئ عن عمل الظل و التحكم به تحكم كامل :
winform.DropShadow
و هذا مثال بسيط عن عمل ظل بسيط للفورم و ظل للبنال و تحكم في زوايا الفورم .
RE: استدعاء method تقوم باضافة ظل للفورم - Rabeea Qbaha - 08-10-19
(08-10-19, 01:34 AM)elgokr كتب : تم مراجعة المرفق ولا يوجد به اى مشكلة
يبدو ان هناك سوء فى بداية الموضوع حيث انه يتحدث صاحب الموضوع
كون الكود يقوم بعمل تظليل للشئ المحدد له ولكن الامر ليس هكذا
كل الامر هو تمكين حركة الاداء وكل ما فعلته هو تحويل الكود
للعمل كا كلاس على اداء طبقاً لما يقوم بتحديده من خلال تغيير هذه الجملة
قد يكون صاحب الموضوع وضع كود بدلاً من كود اخر عند كتابة الموضوع
او هناك خطاء ماء لم انتبه له لعل عند تواجد صاحب الموضوع وضع صورة لشكل الفورم عند تنفيذ الكود
مع ارفاق سورس للشاشة مع الكود لاتمام تحويله الى كلاس
والله اعلم قد اكون انا سهوت عن شئ لم انتبه اليه الى هذه اللحظة
تحياتى لك
وتمنياتى لك التوفيق
مرحبا اخي الجوكر ..
في الحقية الكود الغرض منة اضافة ظل للفورم لتفرقتة عن الفورم الذي خلفة لاني استخدم الكود بخاصية ال border none
في الكود المرفق ايضا موجود خاصية ال drag للفورم وتحريكه عند الضط بالفارة و ايضا تكبير الفورم عند الضعط المزدوج على الفارة
عندكا اريد استخدام الكود اقوم بوضعة في الفورم المحدد وهو امر مزعج ومكرر كثيرا .....
المطلوب هو تحويل الكود ل class اقوم باستدعائة فقط بدل نسخ الكود في اكثر من فورم
|