Класс формы не содержит конструктор, который принимает один аргумент - C#
Формулировка задачи:
Листинг программы
- 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 SingleRemoteDesktop_client_
- {
- public partial class Form1 : Form
- {
- Form2 f2 = new Form2();
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- new Form2(int.Parse(txtport.Text)).Show();
- }
- }
- };
Решение задачи: «Класс формы не содержит конструктор, который принимает один аргумент»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Net.Sockets;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SingleRemoteDesktop
- {
- public partial class Form1 : Form
- {
- private readonly TcpClient client = new TcpClient();
- private NetworkStream mainStream;
- private int portNumber;
- private static Image GrabDesktop()
- {
- Rectangle bounds = Screen.PrimaryScreen.Bounds;
- Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- Graphics graphic = Graphics.FromImage(screenshot);
- graphic.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
- return GrabDesktop();
- }
- private void SendDesktopImage()
- {
- BinaryFormatter binFormatter = new BinaryFormatter();
- mainStream = client.GetStream();
- binFormatter.Serialize(mainStream, GrabDesktop());
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void btnConnect_Click(object sender, EventArgs e)
- {
- portNumber = int.Parse(txtPort.Text);
- try
- {
- client.Connect(txtIP.Text, portNumber);
- MessageBox.Show("Подключено!");
- }
- catch (Exception)
- {
- MessageBox.Show("Не смог подключиться!");
- }
- }
- private void btnSend_Click(object sender, EventArgs e)
- {
- if (btnSend.Text.StartsWith("Просмотр"))
- {
- timer1.Start();
- btnSend.Text = "Остановить просмотр";
- }
- timer1.Stop();
- btnSend.Text = "Показать экран";
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- SendDesktopImage();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д