|
hi,
i want my richtextbox scroll down to show the bottom text after i appended a new text in it automatically.
i did sth similar in VC++ ListBox with SetTopIndex().
would anyone give me some idea how to do it in C# 's RichTextBox control?
thanks,
jim
|
|
|
|
|
i had the same problem before to jim..but i was able to overcome it with something like...
<br />
<br />
public void AppendText(string Message)<br />
{<br />
if(this.TextArea.Text!=null)<br />
this.TextArea.Text +=Message+System.Environment.NewLine;<br />
else<br />
this.TextArea.Text = Message+System.Environment.NewLine;<br />
this.TextArea.Select();<br />
this.TextArea.Select(TextArea.Text.Length-1,TextArea.Text.Length);<br />
this.TextArea.ScrollToCaret();<br />
}<br />
that should fix it.....as always..im sure there might be a better way..but it seemed to work for me.
The Code Project Is Your Friend...
|
|
|
|
|
Set the caret position to the end of the text, and use the ScrollToCaret() method to scroll to the caret position. Be sure to have HideSelection set to false, or it won't work. (I don't know how many times people have asked about why ScrollToCaret doesn't work, when they have HideSelection on! )
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
I am a newbie at design, and I've been studying design patterns but I can't figure what to do in this case.
I have a security object that has properties for a list of fields that also happen to be the properties of another object.
class security {
//"true" value for each property means yes, user has permission to access these fields in client
bool ssNumber;
bool hourlyRate;
bool dateOfBirth;
//getters and setters, functions to pull data from database, etc.
}
class empInfo {
string ssNumber;
decimal hourlyRate;
DateTime dateOfBirth;
//getters and setters, functions to pull data from database, etc.
}
I need empInfo to be aware as to which of its properties are considered permissible for access by a particular user.
What would be the best way to tell if a particular property in empInfo is allowed access by the user?
Should empInfo be extended to include security class and then when empInfo is instantiated and populated, grab security data then?
Since each field represents a datacolumn on the web, I would like to keep as much data manipulation in the middle tier as possible.
Thanks in advance!
|
|
|
|
|
What do you think of this (pseudocode)?:
class empInfo {
string ssNumber;
decimal hourlyRate;
DateTime dateOfBirth;
securitySetter(empInfo) {
securityCollection = security.getSecurity(empInfo);
foreach (property prop in empInfo)
{
foreach {securityItem sItem in securityCollection)
{
if (sItem.access(prop))
{
set.prop = "Not accessible";
}
}
}
return empInfo
}
}
----
I'm concerned about handling the database calls, since building the securityCollection requires a trip to the database, then building the empInfo object requires a trip to the database. Or maybe this cannot be avoided. Cacheing security information for objects would also be memory intensive?
Oh, and important...how can I do this so that ALL empInfo objects in a collection are taken care of for a particular session at one time, without having to re-set for each instantiation?
Any advice is appreciated.
|
|
|
|
|
How do you do that? In C, I would have done something like:
FileAttributes &= ~ReadOnly;
How do I do that in C#?
|
|
|
|
|
|
I want to retain all its previous attributes. Will calling SetAttributes() append this new flag or will it clear all the old ones and set this one?
|
|
|
|
|
This will preserve the old attributes
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.ReadOnly);
|
|
|
|
|
|
I have a window form that contains a textbox. I've hooked into the Validating event of the text box to check that the text is valid and prevent the textbox from lossing focus until valid text is typed. The problem is that if the user clicks a button on the toolbar it completely avoids this validation and this allows the user to get away with invalid input. Is there anyway to prevent this from happening?
|
|
|
|
|
yeah, when user click the button it will generate the required event. so you need to do error checking(validation) in the click event method of the button too.
|
|
|
|
|
So I have to repeat the validation of ALL the controls on my forms when somebody clicks on the toolbar? I'm starting to think the toolbar might not be worth the effort!
|
|
|
|
|
That shouldn't happen! The Validating event is supposed to fire *before* the control loses focus.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
But it does. I just tried it again on a simple application (in case it was something I was doing). I created a form with a textbox, a button and a toolbar with one button. I hooked the textbox validating and the toolbar button like this:
<br />
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)<br />
{<br />
MessageBox.Show("VALIDATING TEXTBOX");<br />
}<br />
<br />
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)<br />
{<br />
MessageBox.Show("CLICK");<br />
}<br />
Now when you run the app and click in the textbox and then tab away (to the regular button) or click the regular button, the VALIDATING messagebox will popup. But if you click the toolbar button, you only see the CLICK messagebox!
|
|
|
|
|
I think the problem is caused because the Toolbar doesn't take the focus away from any controls in the application. An act required for the validation event to fire.
You can fake validation by setting the focus to another control then restoring it. If you just drop a Panel onto your form then you won't even have to deal with something that is visible.
Something like this at the beginning of your ButtonClick event of your ToolBar should work:
Control control = ActiveControl;
if( control != null )
{
panel1.Focus();
if( control != ActiveControl )
{
control.Focus();
}
} HTH,
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
Thanks. I was thinking I'd probably have to do something like that, but I was hoping there might be a more elegant solution.
|
|
|
|
|
I am trying to make a wizard type application. For example, an install application will have multiple forms with a next button to go to the next form. The problem is that I don't know how to jump from form to form without the form being closed and removed from the start taskbar and the next one loaded. This causes continual movement in the taskbar, which is both anoying and potentially confusing to some users. Does anyone know how to go from form to form while keeping the same button in the start taskbar? I have tried to do a MDI type solution but it seems to be more of a pain. Just wondering if there is a typical way to do this.
Mark Sanders
|
|
|
|
|
I can think of a couple of ways you could do this:
The ShowInTaskbar property of a form will prevent it from displaying in the taskbar (when it's set to false). So you could have one blank form, set it to start minimized and prevent it from being maximized, then use that form to open all your other forms (which all have ShowInTaskbar = false) as you need them. No taskbar jiggling should happen.
I think a better way to do it would be to forget about having multiple forms entirely and have just one form with a tab control. You can disable all the tabs so that the pages only get changed programatically when the user clicks the next button. The downside is if you wanted each form to be a different size, although you could make it resize through code it would be a pain to design.
|
|
|
|
|
with regards to the Tab Control solution, is there a way to disable showing the tabs in the form?
thanks
|
|
|
|
|
Hi everyone. I have been creating an application under .NET 2002. I have recently installed .NET 2003 and converted my solution to 2003. I have noticed the following 2 "oddities":
1. Data will not load into a ComboBox that is bound to data from a database and has the Sort property set to true. In .NET 2002, this is okay, at least for the control that had the problem under .NET 2003. I did have some problems with setting Sort to true on a data-bound ComboBox. Workaround: Turned Sort off on that control. All other ComboBoxes load fine with no changes.
2. There are 2 ListBoxes next to each other. The left one is filled with options from the database. When double-clicking an item in the left list, it is removed and then added to the ListBox on the right. However, under .NET 2003, the first entry does not become visible until I add a second item. Workaround: I removed the BeginUpdate and EndUpdate calls from around the double-click logic and it works fine.
So, has anyone see any weird stuff like this? Not major, but I find it odd that the functionality for these has changed like this. The documentation for each item above is the same under .NET 2003, so I think they are bugs. Also, how do I submit bugs to Microsoft without using up my incidents for the year?
BTW, everything functions fine under .NET 2002.
Thanks
abbomar
|
|
|
|
|
i have been trying to figure out a way to send this xml data to ups for rate quotes.
the goal here is to connect to this url, and send data. then receive the data it sends back.
i get an exception because i'm trying to connect to a url ( and subdirectories ) instead of an IP.
how do i connect to this url and send the data to the appropriate place?
here is an example of what i'm attempting:
TcpClient tc=new TcpClient("https://www.ups.com/ups.app/xml/Rate");
NetworkStream ns=tc.GetStream();
StreamWriter sw=new StreamWriter(ns);
sw.WriteLine(xml);
sw.Flush();
StreamReader sr=new StreamReader(ns);
txtResponse.Text = sr.ReadLine();
|
|
|
|
|
I've got a class that does this, it's in hands of editor right now. Don't know when he's going to release it.
Anyway, if you want help, you need to first let us know what the exception was.
norm
|
|
|
|
|
thanks for the reply, .. here is the exception:
System.Net.Sockets.SocketException: The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for
at System.Net.Dns.GetHostByName(String hostName)
at System.Net.Dns.Resolve(String hostName)
at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port)
at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at ups.Form1.btnSend_Click(Object sender, EventArgs e) in c:\visual studio projects\ups\form1.cs:line 202
|
|
|
|