|
You would not be able to call a static variable from another form as it would have been unique to the object form that you had running earlier.
If you need to save information accross instances of your program try saving the information to a file. You can set and get information as you need and it will last until you decide to erase it. Of course, you need to write methods to write and retrieve info, no easy way out. But it will be worth it.
CodeBlind
|
|
|
|
|
It depends, are you writing a Windows Forms or an ASP.NET application? I will assume Windows Forms.
What I do is create a User class that has properties like name, database ID, and anything else you would like to know about a user. It also has a Current static property, which is initializes by a static method taking user name and password. Something like this:
class User
{
private int id;
private string name;
public int Id
{
get { id; }
}
public string Name
{
get { return name; }
}
public User(int id)
{
....
}
static private User current;
public static User Current
{
get { return current; }
}
public static bool LogIn(string userName, string password)
{
if(found)
{
current = new User(foundId);
return true;
}
return false;
}
public static void Logout()
{
current = null;
}
} Then I always have a global object with info about the current user, so I can do things like this:
if(User.Current != null)
sbpUserName.Text = User.Current.Name;
else
sbpUserName.Text = "(please log in)"; I hope this helps! Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Can anyone explain how I can draw a line over an existing image, then later remove it (by redrawing it in some clever way) without having to invalidate and redraw the original image?
|
|
|
|
|
chris fearnley wrote:
without having to invalidate and redraw the original image?
What's the problem? Do you have double buffering on?
David
|
|
|
|
|
David,
Is double buffering relevant?
In MFC, I used CDC::SetROP2 to get a whole range of options about combining pixels. I'm trying to find the equivalent in .NET. Thanks for replying.
|
|
|
|
|
chris fearnley wrote:
Is double buffering relevant?
Well, no . You wrote "(by redrawing it in some clever way) without having to invalidate and redraw the original image?" so I thought that you have performance problem... There was a chance that with double buffering you won't need "clever way" to do it.
Back on topic, if ControlPaint.DrawReversibleLine suggested by Mathew won't work for you, maybe you can interop with GDI. http://pinvoke.net/default.aspx/gdi32/SetROP2.html[^]. It look like there isn't managed solution, but then again I am no GDI/DGI+ expert .
David
|
|
|
|
|
ControlPaint.DrawReversibleLine works fine. A whole new class I didn't know about. Thanks to all.
|
|
|
|
|
|
I want to program realtime streaming ....I have streaming server for run Application and wait client request mpeg file... and I want to use rtsp protocol please tell me for infermation ..(thank you)
t_one
|
|
|
|
|
|
I'm trying to extract Text out of a Rich Edit TextBox. This works differently from a traditional textbox as far as I can tell.
I've been trying to use:
<br />
StringBuilder sb = new StringBuilder(txtLength.ToInt32() + 1);<br />
SendMessage(hWnd,WM_GETTEXT,txtLength,sb);<br />
I know txtLength is the proper length, but the text returned is gibberish. So if any one has ever used SendMessage to take text out of a richedit text box please help me out.
Jake
|
|
|
|
|
Are you trying to get plain text or rich text-encoded string? Also, the built-in RichTextBox returns the plain text via .Text, so I assume you're trying to get text out of a non .NET control, right?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I'm trying to remove text from an external program So I can't use the programs existing structures. I'd prefer some type of streaming system, but I'll take whatever I can get.
|
|
|
|
|
Any example of EditStreamCallback in action would also be useful.
|
|
|
|
|
hey everyone, im new to c# and now a days im trying to work with parallel port. im wana switch two buttons through parallel port with c#... so please help me out...
thanks
|
|
|
|
|
|
I'm trying to compare words entered in a textbox with a selection of stop-words, removing any stopwords that are found. Here's a snippet.
string text = this.textBox1.Text;
if(RemoveMe(s))
{
int startIndex = text.IndexOf(s);
int endIndex = s.Length-1;
text = text.Remove(startIndex, startIndex+endIndex);
}
Problem is, every now and then startIndex get a value of -1...
Kinda stumped here, what am I doing wrong?
|
|
|
|
|
When the iterator reaches the end it sets itself at -1. You need to re-set it at 0 after each string that you are finished with
|
|
|
|
|
int startIndex = text.IndexOf(s);<br />
int endIndex = s.Length-1;<br />
text = text.Remove(startIndex, s.Length);
works fine for me.
Remember the second parameter to "Remove" number of chars to delete, not the endIndex
Can you give us some example strings you are trying to find in "text"?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
hehe...thanks, would have had to be something that simple...
I'm removing common words such as 'at' 'the' 'this' 'is' 'of' etc...
|
|
|
|
|
The IndexOf method returns -1 when the string is not found. You have to check if the word is even present in the string before you try to remove it.
Also, your method is only removing the first occurance of the word. Why don't you use a Replace instead? Or why not use a regular expression? Then you can match the word boundaries, so that you don't accidentally remove a part of a word that matches another word.
---
b { font-weight: normal; }
|
|
|
|
|
I'd use regex but they always leaves me scratching my head somewhat puzzled
Thanks for the suggestions, off to try it in the code now
|
|
|
|
|
They're simple, really
Just take yourself a week and learn it, it's worth a lot when dealing with strings.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yeah, I've kinda put it off long enough
thanks
|
|
|
|
|
Hi there. I'm creating an installer file for the program that I have completed. I want the installer to install the program into the correct folder, etc.
Question:
Does anybody know how to use the tools in Visual Studio to make my "installer.exe" file add a shortcut to the StartUp folder of windows, so that the installed program would run every time a user logs into windows?
Any other alternatives?
thanks.
|
|
|
|