|
Hi Andreas!
The problem seems to be that there's a loop that wont let SetToCaret() work until it's finished.
Then try to call RichTextBox.Refresh() after RichTextBox.ScrollToCaret() .
The loop is lístening to a Socket, while( online ).
Another idea would be to use asynchronous calls to get the data (see Using an Asynchronous Client Socket[^]).
Best regards
Dennis
|
|
|
|
|
|
This has been asked 10 gazillion times, so here goes one solution:
public class RichTextBox : System.Windows.Forms.RichTextBox
{
void ScrollToEnd()
{
const int msg = 0x400 + 222;
int h = Height;
int y = Font.Height * Lines.Length - h;
Point point = new Point(0, y);
SendMessage(Handle, msg, 0, ref point);
}
[DllImport("user32.dll")]
extern static int SendMessage(IntPtr hwnd, int id, int res, ref Point pos);
protected override void OnSizeChanged(EventArgs e)
{
ScrollToEnd();
base.OnSizeChanged (e);
}
protected override void OnTextChanged(EventArgs e)
{
ScrollToEnd();
base.OnTextChanged (e);
}
}
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
leppie wrote:
This has been asked 10 gazillion times, so here goes one solution
I don't see the advantage of using SendMessage instead of the RichTextBox's own methods. Why would you prefer that solution?
Best regards
Dennis
|
|
|
|
|
|
leppie wrote:
Because the methods suppliedin RichTextBox, doesnt work if the control dont have focus, also focusing the control, brings in a host of other issues. Try it!
Well, I did. Where is no need to set the focus. Not with the .NET Framework 2.0. I know it's just the first Beta but hopefully this change will also be in the RTM.
Best regards
Dennis
|
|
|
|
|
|
leppie wrote:
Most people deal with .NET 1.1 unless otherwise specified, what is the point of mentioning it will be fixed, if it is broken currently?
It depends. In case someone needs the functionality right now there is no point. However if someone just started a project which is supposed to be finished in one or two years it would already be worth considering .NET 2.0 specific solutions. Besides it doesn't hurt to learn about new features as soon as possible (that might keep one from using obsolete code later).
Best regards
Dennis
|
|
|
|
|
|
leppie wrote:
Your method also fails to consider that text might be selected in the RTB, so much more work to handle that, now add some color and threads, and you have a nice mess.
Yeah, you're right. But how am I supposed to know if that's required? I guess that's the whole point here. You contributed a solution, I contributed a solution. Yours is a general purpose one. However it depends on Win32 API calls (and therefore isn't platform-independent... yeah, I know... I don't know if that's required either ). Mine has some drawback with complex states of the RichTextBox. But following the Simplicity XP rule[^] (as well as the KISS principle[^]) ScrollToCaret() would still be my first suggestion. If it turns out not to meet the requirements it has to be re-written. You see, if one starts with the more complex solution and it is unnecessary someone might replace it during refactoring anyway (following the Refactor Mercilessly rule[^]).
Best regards
Dennis
|
|
|
|
|
Hello,
My app has 2 methods closing a form. By menu "Exit" and the "X" on the upper right. How can I check, if the "X" Button was clicked and not the menu item "Exit" ?
|
|
|
|
|
May be dull but easy ,
Put a flag for your menuItem which will be set to one by menuItemClick event and directing the call into two methods by checking the flag.
Have a nice day
|
|
|
|
|
Yes dull but easy - (works).
Finally, there must be a way to check this by EventArgs or by sender in the Closing Event ( Property or whatever )
|
|
|
|
|
Do you know some TOM (Text Object Model used by RichTextBox) class for C# ?
Thank you
Wizard_01
|
|
|
|
|
Hi
I got an access database.
is it possible to put the tables of this database in a combobox?
If yes then how?
the underdog
|
|
|
|
|
Hi
Use the following snippet for retrieving table names....
OleDbConnection connection = new OleDbConnection(<connetcionstring>);
connection.Open();
object[] restrictions;
restrictions = new object[] {null , null , null , "TABLE"};
DataTable table;
table = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,restrictions);
connection.Close();
then,
this.cmbTables.DataSource = table;
this.cmbTables.DisplayMember = "TABLE";
I hope it works for you.
|
|
|
|
|
First of all get rid of the new table names stuff and check if you can read data from the tables by using your OleDb code.
Fill some sample data in Access and use
..
.
.
.
.
string sqlSelectStatement = "SELECT * FROM <tablename>";
OleDbDataAdapter adapter = new OleDbDataAdapter =(sqlSelectStatement,connection);
connection.Open();
DataTable table = new DataTable();
try
{
adapter.Fill(table);
}
connection.Close();
Now look in table and tell the result.
|
|
|
|
|
I get the containment of the Table.
So that works as it should
But how to go on now?
The underdog
|
|
|
|
|
If your OleDb code work then as you did last time,
comboBox1.DataSource = table;
combobox1.DisplayMember = columnNameYouWantToListInTheTable as string;
should work.
I dont know what the column name is.
Try some possibilities.
Sorry for incomplete help.
|
|
|
|
|
Hi...
I have some text i want to add to a string!
The text would look like this:
<?xml version="1.0" encoding="utf-8"?>
But i have no idea how to do it... i would do like this:
string a = "<?xml version="1.0" encoding="utf-8"?>";
But that does not work!
Can anyone tell me how to add this to a string..?
Thanks!
QzRz
|
|
|
|
|
Hi,
Put '@' character before the string to inhibate the effect of inner quotes.
string a = @"";
To add a string to another use
String.Concat(string str1 , string str2, .... );
These will work if I got your problem right.
|
|
|
|
|
well... it does not work...
i did this:
string a = @"<?xml version="1.0" encoding="utf-8"?>";
I am using microsoft visual studio .net 2002!
And it puts a red line under '1.0" encoding=@"utf-8"?>"' and i cannot debug!
Do you have another idea of how to solve this...?
Thanks...!
QzRz
|
|
|
|
|
Escape the quotation marks.
string a = "<?xml version=\"1.0\" encoding=\"utf-8\">";
www.troschuetz.de
|
|
|
|
|
Escape the quotation marks.
What does that mean?
do not understand:
string a = "";
QzRz
|
|
|
|
|
Sorry, i forgot to check the "Do not treat <'s as HTML tags" option.
Here it is again.
string a = "<?xml version="1.0" encoding="utf-8"?>";
|
|
|
|