منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : تغير حجم نوافذ برنامج عندما تتغير دقة عرض الشاشة screen resolution
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
لتنفيذ هذه الطريقة في لغة C#، سنقوم بتحويل الخطوات إلى مشروع C# باستخدام WinForms. هذا سيتضمن كتابة فئات ووظائف مشابهة لتلك التي في VB6. فيما يلي شرح لكيفية تنفيذ هذه الطريقة:

إنشاء مشروع جديد في 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<ControlPropertiescontrolList = new List<ControlProperties>();
 
   private int originalFormHeight;
 
   private int originalFormWidth;
 
   private double x_ratio;
 
   private double y_ratio;

 
   private class ControlProperties
    
{
 
       public int Index getset; }
 
       public string Name getset; }
 
       public int Left getset; }
 
       public int Top getset; }
 
       public int Width getset; }
 
       public int Height getset; }
 
   }

 
   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.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 senderEventArgs e)
 
       {
 
           formControl.GetLocation(this);
 
           formControl.ResizeForm(this);

 
           foreach (Control ctrl in this.Controls)
 
           {
 
               ctrl.Font = new Font(ctrl.Font.FontFamilyformControl.SetFontSize());
 
           }
 
       }

 
       private void Form1_Resize(object senderEventArgs e)
 
       {
 
           formControl.ResizeControls(this);

 
           foreach (Control ctrl in this.Controls)
 
           {
 
               ctrl.Font = new Font(ctrl.Font.FontFamilyformControl.SetFontSize());
 
           }
 
       }
 
   }

ويصبح بإمكانك تغيير حجم النافذة وعناصر التحكم بشكل ديناميكي استنادًا إلى دقة عرض الشاشة.