CSHARPWINDOWSFORM Telegram 253
int i = 0;
try
{
if (File.Exists(file))
{


StreamReader reader = new StreamReader(file);


while (!(reader.Peek() == -1))
lines.Add(reader.ReadLine());

i = rnd.Next(lines.Count);


reader.Close();

return lines[i].Trim();
}
else
{

return string.Empty;
}
}
catch (IOException ex)
{
MessageBox.Show("Error: " + ex.Message);
return string.Empty;}}
نشرح اكواد الدالة :

List<string> lines = new List<string>();
قائمة تحتوي على السطور

int i = 0;
متغير للاحتفاظ برقم السطر العشوائي

StreamReader reader = new StreamReader(file);
انشاء اوبجكت لقراءة الملف
while (!(reader.Peek() == -1))
للانتقال عبر كل سطر من ملفنا النصي

lines.Add(reader.ReadLine());
الحصول على رقم سطر عشوائي

reader.Close();
اغلاق الملف النصي

return lines[i].Trim();

الآن اعد نص السطر العشوائي

الان نستدعي الدالة
private void button1_Click(object sender, EventArgs e)
{
string path = " path file txt";
label1.Text = GetRandomLine(ref path);
}
المثال الأخير اختيار لون للفورم بشكل عشوائي

private void button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

BackColor = randomColor;
}

الان عندما تقوم بالتنفيذ
في كل Click على الزر سوف يتم تغيير لون الفورم الى لون مختلف

انتهى.........



tgoop.com/CsharpWindowsForm/253
Create:
Last Update:

int i = 0;
try
{
if (File.Exists(file))
{


StreamReader reader = new StreamReader(file);


while (!(reader.Peek() == -1))
lines.Add(reader.ReadLine());

i = rnd.Next(lines.Count);


reader.Close();

return lines[i].Trim();
}
else
{

return string.Empty;
}
}
catch (IOException ex)
{
MessageBox.Show("Error: " + ex.Message);
return string.Empty;}}
نشرح اكواد الدالة :

List<string> lines = new List<string>();
قائمة تحتوي على السطور

int i = 0;
متغير للاحتفاظ برقم السطر العشوائي

StreamReader reader = new StreamReader(file);
انشاء اوبجكت لقراءة الملف
while (!(reader.Peek() == -1))
للانتقال عبر كل سطر من ملفنا النصي

lines.Add(reader.ReadLine());
الحصول على رقم سطر عشوائي

reader.Close();
اغلاق الملف النصي

return lines[i].Trim();

الآن اعد نص السطر العشوائي

الان نستدعي الدالة
private void button1_Click(object sender, EventArgs e)
{
string path = " path file txt";
label1.Text = GetRandomLine(ref path);
}
المثال الأخير اختيار لون للفورم بشكل عشوائي

private void button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

BackColor = randomColor;
}

الان عندما تقوم بالتنفيذ
في كل Click على الزر سوف يتم تغيير لون الفورم الى لون مختلف

انتهى.........

BY برمجة تطبيقات الويندوز C# Programming


Share with your friend now:
tgoop.com/CsharpWindowsForm/253

View MORE
Open in Telegram


Telegram News

Date: |

Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment. Telegram is a leading cloud-based instant messages platform. It became popular in recent years for its privacy, speed, voice and video quality, and other unmatched features over its main competitor Whatsapp. Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be:
from us


Telegram برمجة تطبيقات الويندوز C# Programming
FROM American