| |

VerySource

 Forgot password?
 Register
Search
View: 1411|Reply: 10

How to read the text of the textBox in the overPaint function?

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-17 22:40:01
| Show all posts |Read mode
I defined a new class, and rewritten the onPaint function in the class. The general structure of the class is as follows:
class PlainForm: Form
{
     protected override void OnPaint (PaintEventArgs e)
     {
      ...........
     }
}
There is a textBox in Form1 (the main form). What can I do to read the text value of the textBox in the overPaint function?
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-23 20:54:02
| Show all posts
Just use TextBox1.Text to get the value.
But why do you want to get this value in OnPaint? Can you tell me your purpose?
Reply

Use magic Report

1

Threads

26

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-23 21:45:01
| Show all posts
Try:
base.TextBox1.Text
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-8 07:00:02
| Show all posts
I want to draw a coordinate chart by overriding onPaint, which requires the user to enter some parameters first. If you directly TextBox1.Text, there will be such an error: "Graphic.Form1.textBox1" means "field", which should be "class" here.
If you change to base.TextBox1.Text, an undefined error occurs, is there any way to solve it?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-6 09:45:02
| Show all posts
Declare Form1's textBox1 as public.
then
Form1 form1 = new Form1 ();
form1.textBox1.Text = "";
such. It is best to get the value of textBox1 by adding a public method or property to Form1, using the design of MVC.
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-3-6 16:15:02
| Show all posts
this.textBox1.Text
Reply

Use magic Report

0

Threads

31

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-7 22:30:01
| Show all posts
Ask, did the textbox have a value before paint?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-13 13:15:01
| Show all posts
Thank you for your help, the value in textBox1 can now be used, but another problem has arisen, if I pre-specify the text value of textBox1 at design time, whatever value you enter at runtime will pass this value, if If you set this value to null during design, you will get the error "The format of the input string is incorrect". What is going on? All depressed and dead.
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-14 16:45:01
| Show all posts
Is the type wrong?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-23 18:15:01
| Show all posts
What does the onPaint function take the value of Textbox for? Generally, the onPaint function does not add any code that has nothing to do with the interface display. What happens when the "input string format is incorrect"?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list