01-06-24, 09:19 PM
لتنفيذ هذه الطريقة في لغة C#، سنقوم بتحويل الخطوات إلى مشروع C# باستخدام WinForms. هذا سيتضمن كتابة فئات ووظائف مشابهة لتلك التي في VB6. فيما يلي شرح لكيفية تنفيذ هذه الطريقة:
إنشاء مشروع جديد في Visual Studio:
افتح Visual Studio وأنشئ مشروع جديد من نوع "Windows Forms App (.NET Framework)".
إضافة كود Module (في C# ستكون كلاس):
أضف كلاس جديد للمشروع وقم بتسميته FormControl. في هذا الكلاس، سنقوم بتعريف المتغيرات والإجراءات اللازمة.
تعريف المتغيرات:
في الكلاس FormControl، سنقوم بتعريف المتغيرات اللازمة كالتالي:
ويصبح بإمكانك تغيير حجم النافذة وعناصر التحكم بشكل ديناميكي استنادًا إلى دقة عرض الشاشة.
إنشاء مشروع جديد في Visual Studio:
افتح Visual Studio وأنشئ مشروع جديد من نوع "Windows Forms App (.NET Framework)".
إضافة كود Module (في C# ستكون كلاس):
أضف كلاس جديد للمشروع وقم بتسميته FormControl. في هذا الكلاس، سنقوم بتعريف المتغيرات والإجراءات اللازمة.
تعريف المتغيرات:
في الكلاس FormControl، سنقوم بتعريف المتغيرات اللازمة كالتالي:
PHP كود :
using System;
using System.Collections.Generic;
using System.Windows.Forms;
public class FormControl
{
private List<ControlProperties> controlList = new List<ControlProperties>();
private int originalFormHeight;
private int originalFormWidth;
private double x_ratio;
private double y_ratio;
private class ControlProperties
{
public int Index { get; set; }
public string Name { get; set; }
public int Left { get; set; }
public int Top { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
public void ResizeForm(Form frm)
{
frm.Height = Screen.PrimaryScreen.Bounds.Height / 2;
frm.Width = Screen.PrimaryScreen.Bounds.Width / 2;
}
public void ResizeControls(Form frm)
{
x_ratio = (double)frm.Height / originalFormHeight;
y_ratio = (double)frm.Width / originalFormWidth;
foreach (Control ctrl in frm.Controls)
{
var properties = controlList.Find(p => p.Name == ctrl.Name);
if (properties != null)
{
ctrl.Left = (int)(properties.Left * y_ratio);
ctrl.Width = (int)(properties.Width * y_ratio);
ctrl.Height = (int)(properties.Height * x_ratio);
ctrl.Top = (int)(properties.Top * x_ratio);
}
}
}
public void GetLocation(Form frm)
{
controlList.Clear();
foreach (Control ctrl in frm.Controls)
{
controlList.Add(new ControlProperties
{
Name = ctrl.Name,
Index = ctrl.TabIndex,
Left = ctrl.Left,
Top = ctrl.Top,
Width = ctrl.Width,
Height = ctrl.Height
});
}
originalFormHeight = frm.Height;
originalFormWidth = frm.Width;
}
public int SetFontSize()
{
if (x_ratio > 0)
{
return (int)(x_ratio * 8);
}
return 8;
}
}
PHP كود :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace screen_result
{
public partial class Form1 : Form
{
private FormControl formControl;
public Form1()
{
InitializeComponent();
formControl = new FormControl();
}
private void Form1_Load(object sender, EventArgs e)
{
formControl.GetLocation(this);
formControl.ResizeForm(this);
foreach (Control ctrl in this.Controls)
{
ctrl.Font = new Font(ctrl.Font.FontFamily, formControl.SetFontSize());
}
}
private void Form1_Resize(object sender, EventArgs e)
{
formControl.ResizeControls(this);
foreach (Control ctrl in this.Controls)
{
ctrl.Font = new Font(ctrl.Font.FontFamily, formControl.SetFontSize());
}
}
}
}
غَزة شجرة سنديان لا تنحني، ووردة لا تذبل، وشوكة عصية على الكسر. غزة، دماؤها تنتصر على السيف والسياف.
متغيب لفترة ان اخطأت بحق احد ارجو المسامحة


