Graphics graph = null;
var bmp = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
graph = Graphics.FromImage(bmp);
graph.CopyFromScreen(0, 0, 0, 0, bmp.Size);
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string path = desktop + @"\ВАЖН0\text\" ;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
bmp.Save(path+"1.jpg",ImageFormat.Jpeg);
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
class Program
{
private const int WM_CAP_DRIVER_CONNECT = 0x40a;
private const int WM_CAP_DRIVER_DISCONNECT = 0x40b;
private const int WS_CHILD = 0x40000000;
private const int WS_POPUP = unchecked((int)0x80000000);
private const int WM_CAP_SAVEDIB = 0x419;
[DllImport("avicap32.dll", EntryPoint = "capCreateCaptureWindowA")]
public static extern IntPtr capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
public static void Main()
{
String dName = "".PadRight(100);
String dVersion = "".PadRight(100);
IntPtr hWndC = capCreateCaptureWindowA("VFW Capture", WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0); // узнать дескриптор камеры
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0); //подключиться к камере
string path = @"D:\test.jpg";
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt32()); // сохранить скриншот
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //отключить камеру
}
}
}
string value = "привет привет hi привет hi";
var counts = value.Split(' ').Distinct().Select(s => s+" = "+ value.Split(' ').Count(z => z == s));
foreach (var item in counts)
Console.WriteLine(item);
привет = 3
hi = 2
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Page", Page),
new KeyValuePair<string, string>("Sides[0]", side1),
new KeyValuePair<string, string>("Sides[1]", side2),
....
};
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Page", Page)
};
for(var i = 0; i < sides.Length;i++)
values.Add( new KeyValuePair<string, string>("Sides["+i+"]", sides[i]));
var responseFile = Encoding.ASCII.GetString(wc.UploadFile(p, @".\TEST\test.txt")); // p - адрес загрузки
Thread t = new Thread(new ParameterizedThreadStart((o) =>
{
Form form = new Form2();
form.ShowDialog();
}));
t.Start();
static void Main()
{
addObject(123, @"D:\out.bin");
addObject(new StringBuilder("lalalla"), @"D:\out.bin");
addObject(new Point(10,20), @"D:\out.bin");
var test = getObjects(@"D:\out.bin");//[int(123),string(lalalal), Point(10,20)]
}
public static void addObject(object obj,string path){
BinaryFormatter formatter = new BinaryFormatter();
List<object> objs = new List<object>();
if (File.Exists(path))
using (FileStream fs = File.Open(path, FileMode.Open))
objs = (List<object>)formatter.Deserialize(fs);
objs.Add(obj);
using (FileStream fs = File.Create(path))
formatter.Serialize(fs,objs);
}
public static List<object> getObjects(string path){
BinaryFormatter formatter = new BinaryFormatter();
List<object> objs = new List<object>();
if (File.Exists(path))
using (FileStream fs = File.Open(path, FileMode.Open))
objs = (List<object>)formatter.Deserialize(fs);
return objs;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await Task.Run( () =>
{
for (int i = 0; i < 101; i++)
{
Dispatcher.Invoke((Action)(() =>
{
label1.Content = i.ToString();
}));
Thread.Sleep(1000);
}
});
}
rewriteLineText(3, @"D:\mytext.txt", "Новое значение");//№ линии, путь к файлу, значение
static void rewriteLineText(int rewriteLine,string path,string str){
FileStream fs = new FileStream(path, FileMode.Open);
var buff = new byte[1];
int byteStart = rewriteLine == 1 ? 0 : -1, byteEnd = -1;
for (int i = 0, line = 1; i < fs.Length; i++){
fs.Read(buff, 0, 1);
if (buff[0] == 10){//10 - перенос строки
if (line == rewriteLine)
{
byteEnd = i;
break;
}
line++;
if (line == rewriteLine)
byteStart = i + 1;
}
if (i == fs.Length - 1)
byteEnd = i;
}
if (byteStart == -1 || byteEnd == -1)
return;
var strByte = Encoding.UTF8.GetBytes(str);
fs.Position = byteEnd;
var tailBuff = new byte[fs.Length - byteEnd];
fs.Read(tailBuff, 0, (int)(fs.Length - byteEnd));
fs.Position = byteStart;
fs.Write(strByte, 0, strByte.Length);
fs.Write(tailBuff, 0, tailBuff.Length);
fs.SetLength(byteStart + strByte.Length + tailBuff.Length);
fs.Close();
}
string[] array = { "Иванов Иван Иванович", "Сидоров Сидор Сидорович", "Петров Петр Петрович" };
var find = "сид";
var finded = array.Where(v => v.Split(' ')[0].ToLower().Contains(find)).ToList();//[0] Сидоров Сидор Сидорович
static void Main() {
StreamReader sr = File.OpenText(@"D:\mytext.txt");
List<string> data = new List<string>();
while (!sr.EndOfStream)
data.Add(sr.ReadLine());
sr.Close();
StreamWriter sw = new StreamWriter(File.Open(@"D:\mytext.txt", FileMode.Create));
var exp = new List<string>() {"a", "o", "а", "о"};
data = data.Select(s => exp.Contains(s.Trim().ToLower()) ? "1" : s).ToList();
foreach (var v in data)
sw.WriteLine(v);
sw.Close();
}
public static void Main()
{
Thread t = new Thread(new ThreadStart(command));
t.Start();
Thread.Sleep(5000);
t.Suspend();
Thread.Sleep(5000);
t.Resume();
Console.ReadKey();
}
public static void command(){
for (var i = 0; i < 10; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(1000);
}
}
public Window()
{
InitializeComponent();
this.textBox.PreviewTextInput += new TextCompositionEventHandler(textBox_PreviewTextInput);
}
void textBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!Char.IsDigit(e.Text,0)) e.Handled = true;
}
int[] firstMas = new int[0];
while (true) {
string userInput = Console.ReadLine();
if (userInput == "exit")
{
break;
}
else if (userInput == "sum")
{
int sum = 0;
for (int i = 0; i < firstMas.Length; i++)
sum += firstMas[i];
Console.WriteLine("Сумма введённых чисел равна " + sum);
}
else
{
int[] secondMas = new int[firstMas.Length + 1];
int number = Convert.ToInt32(userInput);
secondMas[secondMas.Length - 1] = number;
for (int i = 0; i < firstMas.Length; i++)
secondMas[i] = firstMas[i];
firstMas = secondMas;
Console.WriteLine("Длинна массива: " + firstMas.Length);
}
int[] arr = new int[0];
while (true){
string s = Console.ReadLine();
switch (s){
case "exit":
return;
case "sum":
Console.WriteLine(String.Format("Сумма введённых чисел = '{0}'", arr.Sum()));
break;
default:
int result;
if (int.TryParse(s, out result))
arr = arr.Concat(new int[] { result }).ToArray();
break;
}
}
var curId = Process.GetCurrentProcess().Id;
var procName = Process.GetCurrentProcess().ProcessName;
var processes = Process.GetProcesses().Where(p => p.ProcessName == procName && p.Id != curId).ToList();
processes.ForEach(p => p.CloseMainWindow());
int num = 0;
Console.Write("Введите целое число -> ");
int num;
try
{
num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ваше число в квадрате -> " + Math.Pow(Convert.ToDouble(num), 2.0));
}
catch (FormatException)
{
Console.WriteLine("Несоответствие типа.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.CellEndEdit += dataGridView1_CellEndEdit;
}
public void recalculateRow(int rowInx){
var zak = dataGridView1.Rows[rowInx].Cells[0].Value;
var perc = dataGridView1.Rows[rowInx].Cells[1].Value;
dataGridView1.Rows[rowInx].Cells[2].Value = "";
if (zak == null || perc == null)
return;
try{
dataGridView1.Rows[rowInx].Cells[2].Value = float.Parse(zak.ToString()) + float.Parse(zak.ToString()) * (float.Parse(perc.ToString())/100);
}catch(FormatException e){
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
recalculateRow(e.RowIndex);
}
}