This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string readPath = @"D:\read.txt"; //путь для чтения файла | |
string writePath = @"D:\write.txt"; //пусть для записи файла |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//В WPF | |
//В xaml | |
<TextBox InputLanguageManager.InputLanguage="ru-RU" /> | |
//В коде | |
InputLanguageManager.SetInputLanguage(inputTextBox, CultureInfo.CreateSpecificCulture("ru-RU")); | |
//В Windows Form | |
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.CreateSpecificCulture("Ru")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Form1_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
// Обработка момента закрытия формы | |
if (richTextBox1.Modified == false) return; | |
// Если текст модифицирован выясняем записывать ли файл | |
var MBox = MessageBox.Show("Текст был изменен\n" + "Сохранить изменения?", "Простой редактор", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); | |
if (MBox == DialogResult.No) return; | |
if (MBox == DialogResult.Cancel) e.Cancel = true; | |
if (MBox == DialogResult.Yes) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//В WPF | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
newWindow nw = new newWindow(); | |
nw.ShowDialog(); | |
} | |
//В Windows Forms | |
private void button1_Click(object sender, EventArgs e) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Если находится на форме | |
(Controls["textBox1"] as TextBox).Text = "newText"; | |
//если находится в груп боксе | |
groupBox1.Controls["comboBox2"] as ComboBox).Text = "newText"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//В WPF обход всех RadioButton в StackPanel radioStack | |
foreach (UIElement c in radioStack.Children) { | |
if (c is RadioButton) | |
((RadioButton)c).IsChecked = false; | |
} | |
//Пример обхода всех TextBox-ов | |
foreach (Control control in Controls) | |
{ | |
TextBox tb = control as TextBox; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) // нажатие кнопки в поле редактирования | |
{ | |
if ((e.KeyChar >= '0') && (e.KeyChar <= '9')) //разрешение цифр от 0 до 9 | |
return; | |
// в поле редактирование не может быть больше одной точки если вводят запятую меняем ее на точку | |
if (e.KeyChar == ',') e.KeyChar = '.'; | |
if (e.KeyChar == '.') | |
// точка не может быть первым символом | |
{ if((textBox1.Text.IndexOf('.') != -1) || (textBox1.TextLength == 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.IO.StreamReader Reader; | |
Создание потока среамреадер для чтения из файла | |
Reader = new System.IO.StreamReader(openFileDialog1.FileName, System.Text.Encoding.GetEncoding(1251)); | |
textBox1.Text = Reader.ReadToEnd(); Reader.Close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Form1_MouseDown(object sender, MouseEventArgs e) | |
{ | |
// если нажата левая кнопка мыши | |
if (e.Button == MouseButtons.Left) | |
{ | |
moveStart = new Point(e.X, e.Y); | |
} | |
} | |
private void Form1_MouseMove(object sender, MouseEventArgs e) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void печатьToolStripMenuItem_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
Reader = new System.IO.StreamReader(openFileDialog1.FileName, System.Text.Encoding.GetEncoding(1251)); | |
try { printDocument1.Print(); } | |
finally { Reader.Close(); } | |
} | |
catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } | |
} |
OlderNewer