473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why doesnt textbox print or var change?

All,

Being immersed in vb.net and trying CSharp after almost a year I forgot the
differences. I like vb fixing the uppercase/lowercase names and seeming to
be more flexible to code entry.

But while trying to insert a text box to see when a method is used, and
putting a counter to bump some variable?

The textbox sits there unchanged. I put a breakpoint at the text write
command, watching the var countx which stays at 1. If I use countx++ it
stays at zero. In vb I might try me.textbox1.text = "text". If I try
This.textBox1.text = it gets an error saying "This" ? what is that?

//TextBox textBox1 = new TextBox(); But if commented out, it never sees
textBox1

if(pth.IsVisible(pnt))

{

countx = countx+=1;

//countx++;

//countx+=1'

textBox1.Text = "count is : " + countx.ToString() ;

return true;

}
Nov 28 '05 #1
3 2195
Well, first of all, as you pointed out, C# is case sensitive, so the
keyword is 'this', not 'This'.

Second, are you sure that you're not being bitten by the fact that the
text in the TextBox isn't redrawn until after your method returns to
the O/S? While your code is running, if you change the Text property of
TextBox, the TextBox is simply marked as "dirty" to be redrawn later,
when you're finished doing whatever you're doing. If you are running in
a loop and setting the value of the text box as you go, you won't see
it update until the end.

If the problem is that "countx" isn't being updated properly, then you
didn't show us enough code for us to know why, because we can't see
where countx is declared.

Nov 28 '05 #2
Thanks,

here is more of the code, its a drawing program, if I put the breakpoint at
the start of the method, it will break the first time when a line is drawn,
then anytime the mouse is moved over the form area (after its continued)

I will include all the code at the bottom here. I tried "this" but that
doesnt work, I hate to use the excuse of "it works in vb.net" but (it
does). When countx is declared? outside of the method, dont tell me scope
got me also,

public bool IsInLine(Point pnt)

{

Pen p = new Pen(Color.Black,PenWidth);

GraphicsPath pth=new GraphicsPath();

pth.AddLine(StartPoint,EndPoint);

pth.Widen(p);

p.Dispose();

if(pth.IsVisible(pnt))

{

countx = countx+=1;

//textBox1.Text = "count is : " + countx.ToString() ;

//findlines.Line (TTT.Text) = "ddfdfd";

//TextBox TTT;

this.TTT.Text = "fs" + countx.ToString();
return true;

}

// textBox textBox1 = new TextBox();

return false;

}

}

And the entire Form:

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;
namespace findlines

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;
private Line CurrentLine;

private bool AddingLine;

private LineArray Lines=new LineArray();

private Point LastPos;

public System.Windows.Forms.TextBox TTT;

private bool first = true;
public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();
//

// TODO: Add any constructor code after InitializeComponent call

//

}
/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}
#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

this.TTT = new System.Windows.Forms.TextBox();

this.SuspendLayout();

//

// TTT

//

this.TTT.Location = new System.Drawing.Point(104, 16);

this.TTT.Name = "TTT";

this.TTT.Size = new System.Drawing.Size(168, 20);

this.TTT.TabIndex = 0;

this.TTT.Text = ((string)(configurationAppSettings.GetValue("TTT.T ext",
typeof(string))));

this.TTT.TextChanged += new System.EventHandler(this.textBox1_TextChanged);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackColor = System.Drawing.Color.White;

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.TTT);

this.Name = "Form1";

this.Text = "Form1";

this.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseDown);

this.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseUp);

this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_ Paint);

this.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseMove);

this.ResumeLayout(false);

}

#endregion
/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}


private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)

{

CurrentLine = new Line();

CurrentLine.StartPoint=new Point(e.X,e.Y);

AddingLine = true;

}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{

Graphics g=CreateGraphics();
if(!AddingLine)

{

foreach(Line l in Lines)

{

if(l.IsInLine(new Point(e.X,e.Y)))

l.DrawLine(g,Color.Red);

else

l.DrawLine(g,Color.Black);

}

LastPos = new Point(e.X,e.Y);

}

else

{

if(!first)

ControlPaint.DrawReversibleLine(PointToScreen(Curr entLine.StartPoint),
PointToScreen(LastPos), Color.White);

LastPos = new Point(e.X,e.Y);

ControlPaint.DrawReversibleLine(PointToScreen(Curr entLine.StartPoint),
PointToScreen(LastPos), Color.White);

first=false;

}
}
private void Form1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)

{

CurrentLine.EndPoint=new Point(e.X,e.Y);

CurrentLine.PenWidth=5;

Lines.Add(CurrentLine);

AddingLine = false;

Invalidate();

}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)

{

foreach(Line l in Lines)

l.DrawLine(e.Graphics,Color.Black);

}

private void textBox1_TextChanged(object sender, System.EventArgs e)

{
}

}
public class Line

{

public Point StartPoint;

public Point EndPoint;

public int PenWidth;
public void DrawLine(Graphics g,Color c)

{

Pen p=new Pen(c,PenWidth);

g.DrawLine(p,StartPoint,EndPoint);

p.Dispose();

}

TextBox TTT = new TextBox() ;
//TextBox textBox1 = new TextBox();

public int countx = 0; // = 0; // = 0;

// countx = 0;


public bool IsInLine(Point pnt)

{

Pen p = new Pen(Color.Black,PenWidth);

GraphicsPath pth=new GraphicsPath();

pth.AddLine(StartPoint,EndPoint);

pth.Widen(p);

p.Dispose();

if(pth.IsVisible(pnt))

{

countx = countx+=1;

//textBox1.Text = "count is : " + countx.ToString() ;

//findlines.Line (TTT.Text) = "ddfdfd";

//TextBox TTT;

TTT.Text = "fs" + countx.ToString();
return true;

}

// textBox textBox1 = new TextBox();

return false;

}

}
public class LineArray : CollectionBase

{

public void Add(Line l)

{

List.Add(l);

}
public Line this[int index]

{

get{return (Line)List[index];}

set{List[index]=value;}

}

}

}



"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Well, first of all, as you pointed out, C# is case sensitive, so the
keyword is 'this', not 'This'.

Second, are you sure that you're not being bitten by the fact that the
text in the TextBox isn't redrawn until after your method returns to
the O/S? While your code is running, if you change the Text property of
TextBox, the TextBox is simply marked as "dirty" to be redrawn later,
when you're finished doing whatever you're doing. If you are running in
a loop and setting the value of the text box as you go, you won't see
it update until the end.

If the problem is that "countx" isn't being updated properly, then you
didn't show us enough code for us to know why, because we can't see
where countx is declared.

Nov 28 '05 #3
Right, see the problem now, outside of class scope, encapsulation, etc

But then it became a challenge to take data from the other class and cause a
textbox to be changed. Tried with delegates, but it wont see outside its
class either, the addressof wouldnt find the method. If its shared?
addressof finds it, but then you cannot change the textbox.

Just an exercise in scope

"Brad Rogers" <br*************@yahoo.com> wrote in message
news:ciKif.5155$AB2.1297@trnddc08...
Thanks,

here is more of the code, its a drawing program, if I put the breakpoint at the start of the method, it will break the first time when a line is drawn, then anytime the mouse is moved over the form area (after its continued)

I will include all the code at the bottom here. I tried "this" but that
doesnt work, I hate to use the excuse of "it works in vb.net" but (it
does). When countx is declared? outside of the method, dont tell me scope
got me also,

public bool IsInLine(Point pnt)

{

Pen p = new Pen(Color.Black,PenWidth);

GraphicsPath pth=new GraphicsPath();

pth.AddLine(StartPoint,EndPoint);

pth.Widen(p);

p.Dispose();

if(pth.IsVisible(pnt))

{

countx = countx+=1;

//textBox1.Text = "count is : " + countx.ToString() ;

//findlines.Line (TTT.Text) = "ddfdfd";

//TextBox TTT;

this.TTT.Text = "fs" + countx.ToString();
return true;

}

// textBox textBox1 = new TextBox();

return false;

}

}

And the entire Form:

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;
namespace findlines

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;
private Line CurrentLine;

private bool AddingLine;

private LineArray Lines=new LineArray();

private Point LastPos;

public System.Windows.Forms.TextBox TTT;

private bool first = true;
public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();
//

// TODO: Add any constructor code after InitializeComponent call

//

}
/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}
#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

this.TTT = new System.Windows.Forms.TextBox();

this.SuspendLayout();

//

// TTT

//

this.TTT.Location = new System.Drawing.Point(104, 16);

this.TTT.Name = "TTT";

this.TTT.Size = new System.Drawing.Size(168, 20);

this.TTT.TabIndex = 0;

this.TTT.Text = ((string)(configurationAppSettings.GetValue("TTT.T ext",
typeof(string))));

this.TTT.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackColor = System.Drawing.Color.White;

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.TTT);

this.Name = "Form1";

this.Text = "Form1";

this.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseDown);

this.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseUp);

this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_ Paint);
this.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.Form1_ MouseMove);

this.ResumeLayout(false);

}

#endregion
/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}


private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)

{

CurrentLine = new Line();

CurrentLine.StartPoint=new Point(e.X,e.Y);

AddingLine = true;

}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{

Graphics g=CreateGraphics();
if(!AddingLine)

{

foreach(Line l in Lines)

{

if(l.IsInLine(new Point(e.X,e.Y)))

l.DrawLine(g,Color.Red);

else

l.DrawLine(g,Color.Black);

}

LastPos = new Point(e.X,e.Y);

}

else

{

if(!first)

ControlPaint.DrawReversibleLine(PointToScreen(Curr entLine.StartPoint),
PointToScreen(LastPos), Color.White);

LastPos = new Point(e.X,e.Y);

ControlPaint.DrawReversibleLine(PointToScreen(Curr entLine.StartPoint),
PointToScreen(LastPos), Color.White);

first=false;

}
}
private void Form1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)

{

CurrentLine.EndPoint=new Point(e.X,e.Y);

CurrentLine.PenWidth=5;

Lines.Add(CurrentLine);

AddingLine = false;

Invalidate();

}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

foreach(Line l in Lines)

l.DrawLine(e.Graphics,Color.Black);

}

private void textBox1_TextChanged(object sender, System.EventArgs e)

{
}

}
public class Line

{

public Point StartPoint;

public Point EndPoint;

public int PenWidth;
public void DrawLine(Graphics g,Color c)

{

Pen p=new Pen(c,PenWidth);

g.DrawLine(p,StartPoint,EndPoint);

p.Dispose();

}

TextBox TTT = new TextBox() ;
//TextBox textBox1 = new TextBox();

public int countx = 0; // = 0; // = 0;

// countx = 0;


public bool IsInLine(Point pnt)

{

Pen p = new Pen(Color.Black,PenWidth);

GraphicsPath pth=new GraphicsPath();

pth.AddLine(StartPoint,EndPoint);

pth.Widen(p);

p.Dispose();

if(pth.IsVisible(pnt))

{

countx = countx+=1;

//textBox1.Text = "count is : " + countx.ToString() ;

//findlines.Line (TTT.Text) = "ddfdfd";

//TextBox TTT;

TTT.Text = "fs" + countx.ToString();
return true;

}

// textBox textBox1 = new TextBox();

return false;

}

}
public class LineArray : CollectionBase

{

public void Add(Line l)

{

List.Add(l);

}
public Line this[int index]

{

get{return (Line)List[index];}

set{List[index]=value;}

}

}

}



"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Well, first of all, as you pointed out, C# is case sensitive, so the
keyword is 'this', not 'This'.

Second, are you sure that you're not being bitten by the fact that the
text in the TextBox isn't redrawn until after your method returns to
the O/S? While your code is running, if you change the Text property of
TextBox, the TextBox is simply marked as "dirty" to be redrawn later,
when you're finished doing whatever you're doing. If you are running in
a loop and setting the value of the text box as you go, you won't see
it update until the end.

If the problem is that "countx" isn't being updated properly, then you
didn't show us enough code for us to know why, because we can't see
where countx is declared.


Nov 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Gray | last post by:
Greetings all, I'm working on a program that allows a user to enter notes in a multiline textbox. I would like to be able to read the contents of the textbox (as records - one per line) and...
12
by: Robert | last post by:
As a pre-newbie to visual basic, I haven't programmed for years and I am having the greatest of difficulties coping with it. If any kind soul can help me out with advice then I'd be most grateful....
1
by: Daniel | last post by:
when i set the BackgroundImage property in the designer the image still doesnt show in the background of the textbox any other property must be set?
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
1
by: Solitus | last post by:
I have a form for a customer to edit his customer information. It has several textboxes that I will populate with some existing data from the database before displaying the form to the user. I...
6
by: Frank | last post by:
Hopefully this is the correct group for this message. My previous post to (I assume) a non-.net group was not welcomed. I have a form with 7 text boxes that are all bound to fields of a...
2
by: Showjumper | last post by:
I have a problem. Somecontrol.Attributes.Add is not working for me nor is page.registerclientscriptblock. I have created a script using the stringbuilder class. Then when i try to register it on...
4
by: mdarling | last post by:
I am using Lebans lady example to mix Bold and Normal in a single line text box, I have altered it and I still cant get it to bold the text I need bolded I have pasted it here, can somebody help? I...
6
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.