السلام عليكم ورحمة الله وبركاته
يعطيكم العافية لو تكرمتو احتاج تعديل هذا المثال الى #C من VB
هو عبارة عن كلاس واكواد لتكبير الفورم
لكم مني جزيل الشكر
(24-06-19, 11:02 PM)hglogtd كتب : [ -> ]السلام عليكم ورحمة الله وبركاته
يعطيكم العافية لو تكرمتو احتاج تعديل هذا المثال الى #C من VB
هو عبارة عن كلاس واكواد لتكبير الفورم
لكم مني جزيل الشكر
(لست مبرمج #C)
تم تحويل الكود بالاستعانة بموقع
Code Converter C# to VB and VB to C# – Telerik
كود :
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
public class ResizeControls
{
private Hashtable RatioTable = new Hashtable();
private float WindowHeight;
private float WindowWidth;
private float HeightRatio;
private float WidthRatio;
private Control _Container = new Control();
private static long m_FormWidth; // Original form width.
private static long m_FormHeight;
public Control Container
{
get
{
return _Container;
}
set
{
_Container = Ctrl;
FullRatioTable();
}
}
private struct SizeRatio
{
public float TopRatio;
public float LeftRatio;
public float HeightRatio;
public float WidthRatio;
}
private void FullRatioTable()
{
WindowHeight = _Container.Height;
WindowWidth = _Container.Width;
RatioTable = new Hashtable();
AddChildrenToTable(ref _Container);
}
private void AddChildrenToTable(ref Control ChildContainer)
{
SizeRatio R = new SizeRatio();
foreach (Control C in ChildContainer.Controls)
{
{
var withBlock = C;
R.TopRatio = System.Convert.ToSingle(withBlock.Top / (double)WindowHeight);
R.LeftRatio = System.Convert.ToSingle(withBlock.Left / (double)WindowWidth);
R.HeightRatio = System.Convert.ToSingle(withBlock.Height / (double)WindowHeight);
R.WidthRatio = System.Convert.ToSingle(withBlock.Width / (double)WindowWidth);
RatioTable(withBlock.Name) = R;
if (withBlock.HasChildren)
AddChildrenToTable(ref C);
}
}
}
public void ResizeControls()
{
HeightRatio = System.Convert.ToSingle(_Container.Height / (double)WindowHeight);
WidthRatio = System.Convert.ToSingle(_Container.Width / (double)WindowWidth);
WindowHeight = _Container.Height;
WindowWidth = _Container.Width;
ResizeChildren(ref _Container);
}
private void ResizeChildren(ref Control ChildContainer)
{
SizeRatio R = new SizeRatio();
foreach (Control C in ChildContainer.Controls)
{
{
var withBlock = C;
R = (SizeRatio)RatioTable(withBlock.Name);
withBlock.Top = System.Convert.ToInt32(WindowHeight * R.TopRatio);
withBlock.Left = System.Convert.ToInt32(WindowWidth * R.LeftRatio);
withBlock.Height = System.Convert.ToInt32(WindowHeight * R.HeightRatio);
withBlock.Width = System.Convert.ToInt32(WindowWidth * R.WidthRatio);
if (withBlock.HasChildren)
ResizeChildren(ref C);
}
switch (true)
{
case object _ when C is ListBox:
{
ListBox L = new ListBox();
L = (ListBox)C;
L.IntegralHeight = false;
break;
}
}
ResizeControlFont(ref C, WidthRatio, HeightRatio);
}
}
public static void SubResize(Form F, float percentW, float percentH)
{
long FormHeight;
long FormWidth;
float HeightChange;
float WidthChange;
FormHeight = Int((Screen.PrimaryScreen.WorkingArea.Height) * (percentH / (double)100));
FormWidth = Int((Screen.PrimaryScreen.WorkingArea.Width) * (percentW / (double)100));
{
var withBlock = F;
withBlock.Height = FormHeight;
withBlock.Width = FormWidth;
HeightChange = withBlock.ClientSize.Height / (double)m_FormHeight;
WidthChange = withBlock.ClientSize.Width / (double)m_FormWidth;
}
}
private void ResizeControlFont(ref Control Ctrl, float RatioW, float RatioH)
{
float FSize = Ctrl.Font.Size;
FontStyle FStyle = Ctrl.Font.Style;
string FNome = Ctrl.Font.Name;
float NewSize = FSize;
NewSize = System.Convert.ToSingle(FSize * Math.Sqrt(RatioW * RatioH));
Font NFont = new Font(FNome, System.Convert.ToSingle(NewSize), FStyle);
Ctrl.Font = NFont;
}
}
عملت له تحويل مثل ما عملت انت لكن اعطاني اخطاء كثيرة
(25-06-19, 03:17 AM)hglogtd كتب : [ -> ]عملت له تحويل مثل ما عملت انت لكن اعطاني اخطاء كثيرة
(لست مبرمج #C)
يمكنك تحويل كلاس VB.NET هذا إلى مكتبة DLL عن طريق مشروع Class Library في VB.NET،
ومن ثم إدراجه واستدعائه في مشروع #C