05-10-18, 02:04 PM
قد فكرت فى طريقة وهى ان اجعل لكل صفحة كلاس خاص بة من اليبل
ولكن المشكلة هى كيف استدعى فى كل مرة هذة الكلاس من دون استخدام قاعدة IF او قادة switch
كل ما اريدة الان ان اجد طريقة لستدعاء الكلاس برقم الصفحة
يعنى الصفحة رقم واحد
اخذ رقم اصفحة وادمجة مع جزء من اسم الكلاس فاستدعى الكلاس المطلوب
لان المصحف 604 صفحة لن ينفع قاعدة IF او قادة switch
ارجوا الرد
كود :
var p = new Page_1(Page);
p.eMouseLeave += this.LBL_S1_A6_2_MouseLeave;
p.eMouseClick += this.LBL_S1_A1_MouseClick;
p.eMouseHover += this.LBL_S1_A6_2_MouseHover;كود :
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace QuranLibrary.ClassPages
{
public delegate void dMouseLeave(object sender, EventArgs e);
public delegate void dMouseHover(object sender, EventArgs e);
public delegate void dMouseClick(object sender, MouseEventArgs e);
public class Page_1 : Panel
{
public Color ColorMouseHover = Color.FromArgb(70, 185, 215, 252);
public Color ColorMouseLeave = Color.FromArgb(0, 255, 255, 255);
public event dMouseLeave eMouseLeave = null;
public event dMouseHover eMouseHover = null;
public event dMouseClick eMouseClick = null;
private Label Page1_S0_A0;
private Label Page1_S0_A1;
private Label Page1_S0_A5_2;
private Label Page1_S0_A5_1;
private Label Page1_S0_A4;
private Label Page1_S0_A3;
private Label Page1_S0_A2;
private Label Page1_S0_A6_3;
private Label Page1_S0_A6_2;
private Label Page1_S0_A6_1;
public Page_1 (int ImageNum1)
{
this.Page1_S0_A5_2 = new Label();
this.Page1_S0_A5_1 = new Label();
this.Page1_S0_A4 = new Label();
this.Page1_S0_A3 = new Label();
this.Page1_S0_A2 = new Label();
this.Page1_S0_A1 = new Label();
this.Page1_S0_A0 = new Label();
this.Page1_S0_A6_1 = new Label();
this.Page1_S0_A6_2 = new Label();
this.Page1_S0_A6_3 = new Label();
// panel1
//
this.BackgroundImage = Image.FromFile(Application.StartupPath + string.Format("\\images\\{0}.PNG", ImageNum1));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.Controls.Add(this.Page1_S0_A6_3);
this.Controls.Add(this.Page1_S0_A6_2);
this.Controls.Add(this.Page1_S0_A6_1);
this.Controls.Add(this.Page1_S0_A5_2);
this.Controls.Add(this.Page1_S0_A5_1);
this.Controls.Add(this.Page1_S0_A4);
this.Controls.Add(this.Page1_S0_A3);
this.Controls.Add(this.Page1_S0_A2);
this.Controls.Add(this.Page1_S0_A1);
this.Controls.Add(this.Page1_S0_A0);
this.AutoScroll = true;
this.Dock = System.Windows.Forms.DockStyle.Fill;
this.Location = new System.Drawing.Point(0, 0);
this.Size = new System.Drawing.Size(462, 673);
this.Name = "Page_1";
this.TabIndex = 0;
//
// Page1_S1_A7_3
//
this.Page1_S0_A6_3.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A6_3.Location = new System.Drawing.Point(186, 446);
this.Page1_S0_A6_3.Name = "Page1_S0_A6_3";
this.Page1_S0_A6_3.Size = new System.Drawing.Size(93, 21);
this.Page1_S0_A6_3.TabIndex = 9;
this.Page1_S0_A6_3.Text = " ";
this.Page1_S0_A6_3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A6_3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A6_3.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A6_3.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A7_2
//
this.Page1_S0_A6_2.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A6_2.Location = new System.Drawing.Point(155, 421);
this.Page1_S0_A6_2.Name = "Page1_S0_A6_2";
this.Page1_S0_A6_2.Size = new System.Drawing.Size(149, 21);
this.Page1_S0_A6_2.TabIndex = 8;
this.Page1_S0_A6_2.Text = " ";
this.Page1_S0_A6_2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A6_2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A6_2.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A6_2.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A7_1
//
this.Page1_S0_A6_1.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A6_1.Location = new System.Drawing.Point(125, 397);
this.Page1_S0_A6_1.Name = "Page1_S0_A6_1";
this.Page1_S0_A6_1.Size = new System.Drawing.Size(93, 21);
this.Page1_S0_A6_1.TabIndex = 7;
this.Page1_S0_A6_1.Text = " ";
this.Page1_S0_A6_1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A6_1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A6_1.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A6_1.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A6_2
//
this.Page1_S0_A5_2.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A5_2.Location = new System.Drawing.Point(233, 397);
this.Page1_S0_A5_2.Name = "Page1_S0_A5_2";
this.Page1_S0_A5_2.Size = new System.Drawing.Size(93, 21);
this.Page1_S0_A5_2.TabIndex = 6;
this.Page1_S0_A5_2.Text = " ";
this.Page1_S0_A5_2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A5_2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A5_2.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A5_2.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A6_1
//
this.Page1_S0_A5_1.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A5_1.Location = new System.Drawing.Point(115, 368);
this.Page1_S0_A5_1.Name = "Page1_S0_A5_1";
this.Page1_S0_A5_1.Size = new System.Drawing.Size(48, 21);
this.Page1_S0_A5_1.TabIndex = 5;
this.Page1_S0_A5_1.Text = " ";
this.Page1_S0_A5_1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A5_1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A5_1.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A5_1.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A5
//
this.Page1_S0_A4.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A4.Location = new System.Drawing.Point(164, 368);
this.Page1_S0_A4.Name = "Page1_S0_A4";
this.Page1_S0_A4.Size = new System.Drawing.Size(174, 21);
this.Page1_S0_A4.TabIndex = 4;
this.Page1_S0_A4.Text = " ";
this.Page1_S0_A4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A4.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A4.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A4.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A4
//
this.Page1_S0_A3.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A3.Location = new System.Drawing.Point(118, 340);
this.Page1_S0_A3.Name = "Page1_S0_A3";
this.Page1_S0_A3.Size = new System.Drawing.Size(111, 21);
this.Page1_S0_A3.TabIndex = 3;
this.Page1_S0_A3.Text = " ";
this.Page1_S0_A3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A3.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A3.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A3
//
this.Page1_S0_A2.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A2.Location = new System.Drawing.Point(236, 340);
this.Page1_S0_A2.Name = "Page1_S0_A2";
this.Page1_S0_A2.Size = new System.Drawing.Size(93, 21);
this.Page1_S0_A2.TabIndex = 2;
this.Page1_S0_A2.Text = " ";
this.Page1_S0_A2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A2.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A2.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A2
//
this.Page1_S0_A1.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A1.Location = new System.Drawing.Point(144, 317);
this.Page1_S0_A1.Name = "Page1_S0_A1";
this.Page1_S0_A1.Size = new System.Drawing.Size(166, 21);
this.Page1_S0_A1.TabIndex = 1;
this.Page1_S0_A1.Text = " ";
this.Page1_S0_A1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A1.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A1.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
// Page1_S1_A1
//
this.Page1_S0_A0.BackColor = System.Drawing.Color.Transparent;
this.Page1_S0_A0.Location = new System.Drawing.Point(161, 288);
this.Page1_S0_A0.Name = "Page1_S0_A0";
this.Page1_S0_A0.Size = new System.Drawing.Size(141, 21);
this.Page1_S0_A0.TabIndex = 0;
this.Page1_S0_A0.Text = " ";
this.Page1_S0_A0.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Page1_S0_A0.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Page1_S1_A7_3_Click);
this.Page1_S0_A0.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
this.Page1_S0_A0.MouseHover += new System.EventHandler(this.label1_MouseHover);
//
}
private void label1_MouseHover(object sender, EventArgs e)
{
if (eMouseHover != null) eMouseHover(sender, e);
Label lb = (Label)sender;
//if (lb.Name == "Page1_S1_A1")
// Page1_S0_A1.BackColor = ColorMouseHover;
//if (lb.Name == "Page1_S1_A2")
// Page1_S0_A2.BackColor = ColorMouseHover;
//if (lb.Name == "Page1_S1_A3")
// Page1_S0_A3.BackColor = ColorMouseHover;
//if (lb.Name == "Page1_S1_A4")
// Page1_S0_A4.BackColor = ColorMouseHover;
//if (lb.Name == "Page1_S1_A5")
// Page1_S0_A5.BackColor = ColorMouseHover;
if (lb.Name == "Page1_S0_A5_1")
{
Page1_S0_A5_1.BackColor = ColorMouseHover;
Page1_S0_A5_2.BackColor = ColorMouseHover;
}
if (lb.Name == "Page1_S0_A6_1")
{
Page1_S0_A6_1.BackColor = ColorMouseHover;
Page1_S0_A6_2.BackColor = ColorMouseHover;
Page1_S0_A6_3.BackColor = ColorMouseHover;
}
}
private void label1_MouseLeave(object sender, EventArgs e)
{
Label lb = (Label)sender;
if (eMouseLeave != null) eMouseLeave(sender, e);
//if (lb.Name == "Page1_S1_A1")
// Page1_S1_A1.BackColor = ColorMouseLeave;
//if (lb.Name == "Page1_S1_A2")
// Page1_S0_A2.BackColor = ColorMouseLeave;
//if (lb.Name == "Page1_S1_A3")
// Page1_S0_A3.BackColor = ColorMouseLeave;
//if (lb.Name == "Page1_S1_A4")
// Page1_S0_A4.BackColor = ColorMouseLeave;
//if (lb.Name == "Page1_S1_A5")
// Page1_S0_A5.BackColor = ColorMouseLeave;
if (lb.Name == "Page1_S0_A5_1")
{
Page1_S0_A5_1.BackColor = ColorMouseLeave;
Page1_S0_A5_2.BackColor = ColorMouseLeave;
} if (lb.Name == "Page1_S0_A6_1")
{
Page1_S0_A6_1.BackColor = ColorMouseLeave;
Page1_S0_A6_2.BackColor = ColorMouseLeave;
Page1_S0_A6_3.BackColor = ColorMouseLeave;
}
}
private void Page1_S1_A7_3_Click(object sender, MouseEventArgs e)
{
if (eMouseClick != null) eMouseClick(sender, e);
}
}
}كل ما اريدة الان ان اجد طريقة لستدعاء الكلاس برقم الصفحة
يعنى الصفحة رقم واحد
كود :
var sName = string.Format("Page_{0}", Page);
var p = new sName (Page);
p.eMouseLeave += this.LBL_S1_A6_2_MouseLeave;
p.eMouseClick += this.LBL_S1_A1_MouseClick;
p.eMouseHover += this.LBL_S1_A6_2_MouseHover;لان المصحف 604 صفحة لن ينفع قاعدة IF او قادة switch
ارجوا الرد

