|
do u mean the color appears in the textbox itself or in the printable copy.?
ByMindOnlyYouCanDoIt
|
|
|
|
|
both, in a richtextbox though
IM PROUD TO BE A GMAIL;
|
|
|
|
|
How can I show the images in database (sqlserver) on the Windows Form ???
|
|
|
|
|
You will need datasource and some control able to display data from your datasource.
You can build your datasource using regular SqlDataAdapter (just drop your table on the form) and then generate dataset. Add OnLoad or button event and fill your dataset.
Displaying data is a little bit more complicated since there is no standard control able to do that. There are several solutions:
1. Easiest one - download VB resource kit from Microsoft site. You can find a ComponentOne Studio.NET controls (quite old but full version and free) there. There is some clever control named C1PictureBox which you can bind directly to field containing your image data
2. You can write your own control. You can do that overloading PictureBox control and using byte array, image class and binding events (optional). I think, someone wrote great article about it - it was example of using Northwind pictures in windows forms - try to search for it.
|
|
|
|
|
How can I find out which the method name at run time?
For example:
Class Foo
{
int DoSomething()
{
//here is where I need to find out this method name at run time
}
}
|
|
|
|
|
some stackframe or stackview class will help u...
also u can use reflection
|
|
|
|
|
StackTrace trace = new StackTrace(0);
string currentMethodName = trace.GetFrame(0).GetMethod().Name;
string callingMethod = trace.GetFrame(1).GetMethod().Name;
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi!
I have a richtextbox with a vertical scrollbar. My problem is that the scrollbar is always at the top. How do I get the scrollbar to always be down, showing the lastest added text?
Andreas Färnstrand
|
|
|
|
|
Hi Andreas!
I have a richtextbox with a vertical scrollbar. My problem is that the scrollbar is always at the top.
You can use the TextBoxBase.ScrollToCaret [^] method.
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionLength = 0;
richTextBox1.ScrollToCaret();
Best regards
Dennis
|
|
|
|
|
Hi Dennis!
Thanks for your help. It doesn't seem to work though. Here's my code:
private void Print(string text){
this.messagesrichtextbox.AppendText(text + "\n");
this.messagesrichtextbox.SelectionStart = this.messagesrichtextbox.Text.Length;
this.messagesrichtextbox.SelectionLength = 0;
this.messagesrichtextbox.ScrollToCaret();
}
Simple enough, but it won't work. I've tried adding a this.messagesrichtextbox.Select also but it didn't work either.
What's wrong?
Thanx,
Andreas
Andreas Färnstrand
|
|
|
|
|
Hi Andreas!
Thanks for your help. It doesn't seem to work though.
Well, I've tested this using VS 2005 so this difference in the behaviour could be due to chances made to the .NET Framework 2.0. Try setting the focus to the RichTextBox before calling ScrollToCaret (right now I don't have the Framework 1.1 installed so I can't verfiy if that's the problem). If this solves your problem you might want to add a few lines to restore the focus after scrolling the text.
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectionLength = 0;
richTextBox1.Focus();
richTextBox1.ScrollToCaret();
Best regards
Dennis
|
|
|
|
|
Hi again!
I'm sorry! It does work. The problem seems to be that there's a loop that wont let SetToCaret() work until it's finished. You can add text to the richtextbo but it doesn't scroll down until I shut the loop down. The loop is lístening to a Socket, while( online ).
Thanks again,
Andreas
Andreas Färnstrand
|
|
|
|
|
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 )
|
|
|
|