|
Luc, thanks for the tips, I have already used in my other forms in the same program:
RichTextBox Tb = Tc.SelectedTab.Controls[0] as RichTextBox;
Tb.LoadFile(Of.FileName, RichTextBoxStreamType.PlainText);
Tc.SelectedTab.Text = Of.SafeFileName;
.. I honestly have no idea why i didn't do it that way in the program.cs file lol. Ah... To answer your first question, I've read a few articles on args months ago and never really used what I learned up until a few days ago and I've forgotten most of what I learned and now I can't seem to find that article It must be hiding from me...
|
|
|
|
|
Thanks luc I solved my problem... here's what I came up with:
Program.cs File:
frm.Tb.Tag = (args[0]);
Form1 File (SPage):
Tc.SelectedTab.Text = Tb.Tag.ToString();
Thanks pete, luc and nagy for your help!
jase
|
|
|
|
|
I am trying to make a timmer that refreshes the dot on a button at half second intervals.
I added "this.Refresh" to do so however it creates the following error.
Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
i called this.Refresh inside a method:
void m_mouseTimer_Tick(object sender, EventArgs e)
{
if(m_mouseClicked == true)
{
m_spotLocation = new Point( MousePosition.X, MousePosition.Y);
}
}
Does anyone know what im doing wrong here
|
|
|
|
|
'Refresh' is a method and must be called as one: this.Refresh();
I think you're on the right track.
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
Ah yes thank you for the help. It works fine now.
Im unsure about my method of rotating the dot on the button. does anyone have an idea as to how i can make a dot move round the outside of the button depending on where the mouse is (MouseDown Event).
It will be a set distance say 10mm from the edge of the button and will need to stay at that distance while traveling the circumfrence.
Current Process:
DrawButton()Draws button
MouseDown() event true or false
Timmer() ticks every half second and refreshes If mouseDown true re position spot
I have searched the net everywhere but have not found any examples.
|
|
|
|
|
I guess you'll have to use your 10th grade geometry/math skills. You have a circle, a point, say X, in the same plane, and you want to find the point where the line from X to the center of the circle meets the circle.
If you could somehow derive equations for a circle and a line, then solving the equations should give you that point of intersection.
|
|
|
|
|
Sorry for the indescriptive title in advance, I figured that is what suited the problem at hand best.
I'm creating a menu based off a data source and dynamically adding buttons. The width of the menu should be set by the 'longest' string that is to be displayed on any of the buttons, so my question is how do i know what size to set my button to based off of the text to be displayed?
An example of such would be the following string array:
"Help"
"Option 1"
"This is a longer option"
All buttons should be set to have a width wide enough to display "This is a longer option" so that all menu buttons have an equal width. My question, how do I translate that string of text into a width in pixels to resize my button to?
If my problem is not descriptive or clear enough, sorry in advance and I'd be happy to clear anything up. Thanks for the view in advance.
|
|
|
|
|
1) Get a Graphics object from the control that will host the text
Graphics gr = menuButton1.CreateGraphics();
2) Use the MeasureString method of the Graphics object obtained above
SizeF buttonTextSize = gr.MeasureString("yourstring", menuButton1.Font, etc......);
Can't remember all params, look it up.
Add required margin size to buttonTextSize.Width, and Bobs your Aunties' SO.
[Edit]
Don't forget to dispose the Graphics object when done
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Dim g As System.Drawing.Graphics = NewSubItem.ControlTextButton.CreateGraphics
Dim s As System.Drawing.SizeF
s = g.MeasureString(NewSubItem.ControlTextButton.Text, NewSubItem.ControlTextButton.Font)
Got it, thanks.
|
|
|
|
|
If you are using Windows Forms buttons, the easiest way is probably to use the AutoSize property. For example:
Button b = new Button();
b.AutoSize = true;
b.Text = "My longest text";
You can then retrieve the button's size using b.Size.Width and b.Size.Height , record the maximum values, tweak them if necessary, and then apply them to all of your buttons:
foreach (Button myb in MyButtons)
{
myb.Size = new Size(maxwidth, maxheight);
}
Of course you must also change the buttons' positions accordingly (myb.Location = new Point(x, y) ).
If the controls you are using don't have an AutoSize property, then you must get the font and calculate the string's size. You can Google for that.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
This method was not valid for me as my buttons are not the standard control belonging to the System.Windows.Forms.Button class. My controls are composed of multiple other controls and I've been editing them for some time to implement new desired behavior without breaking the current implementation.
This was the last step, and it's done.
Going to have a cold one tonight!
|
|
|
|
|
Hello everybody,
I need a method in c# to transform non english word to a unique string representation. The method should detect if the word contains non english characters and, only in that case it converts the word to diffrent representation, the algo is the following:
String transformString(String inputString)
{
if(inputString.containsNonEnglishChar())
{
String res = "";
foreach(char ch in inputString)
{
res += transformChar(ch);
}
return res;
}
return inputString;
}
I can write the method my way, but I prefer to find something standard, like base 64 or URL encoding or something famous.
Thanks in advance.
HZ
|
|
|
|
|
The System.Char structure [^] has some properties like IsLetter .
Probably there are similar functions that are culture aware, for which you basically pass some English culture (e.g. "en-US") and then call "IsLetter " and get a true /false if it is or not.
|
|
|
|
|
Thanks man,
I can know if a char is in the ASCII range,
I can do this: if((int)ch <= 255), and this is sufficient in my case, but I try to find a better way to encode the string like the url format. As Does the HttpServerUtility.UrlEncode method.
But I cannot add a reference to the System.web namespace, I have to find some alternative.
Thanks for your advice.
HZ
|
|
|
|
|
HZ_79 wrote: I cannot add a reference to the System.web namespace
Why is it so?
just do: Solution Pane/Add Reference/.NET/System.Web
then insert a using statement.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
One possibility to encode all non-ASCII characters is to use UTF-7[^]:
encode: Encoding.ASCII.GetString(Encoding.UTF7.GetBytes(text))
decode: Encoding.UTF7.GetString(Encoding.ASCII.GetBytes(encodedString))
modified on Wednesday, June 3, 2009 10:55 AM
|
|
|
|
|
I am using vs2003, i want to edit, delete , create some entries in registry thru coding, i read some article here & on others sites too. And doing this fine.
But if i make some changes in registry, then i have to restart pc for them to take effects.
a) Is there any way to update/Reload registry, without restarting pc?
b) Also, How to Reload whole window OS without restart?
any link, help would be appreciated.
regards.
|
|
|
|
|
You don't "reload the Registry". You have to notify or reload the component that uses those registry values to get it to see the changes, IF that component exposes such functionality. If not, you have no choice but to restart the system for those changes to take effect.
What changes are you making??
|
|
|
|
|
Dave Kreskowiak wrote: What changes are you making??
I am deleting some registry entries used by an application.
But even if the entries got deleted the application keeps on running until it restarts.
So, Isn't there a way to do this thru coding?
(like when we install some application then upon complete installation, the whole explorer(all open windows) got refreshed, i think it reloading os/reg)
Dave Kreskowiak wrote: You have to notify or reload the component that uses those registry values to get it to see the changes,
How can i notify an application to check or reload itself?
regards
|
|
|
|
|
Hum Dum wrote: So, Isn't there a way to do this thru coding?
(like when we install some application then upon complete installation, the whole explorer(all open windows) got
The O/S and/or Explorer and/or the registry does NOT get reloaded right before the users eyes.
Hum Dum wrote: How can i notify an application to check or reload itself?
The notification method, if any, depends on what needs to be notified. For example, changing the background image is a broadcast message to Explorer sent using a specific API in Windows. But, this method ONLY works if the app (Explorer) is listening for it. It will NOT work with other applications.
Hum Dum wrote: I am deleting some registry entries used by an application.
But even if the entries got deleted the application keeps on running until it restarts.
This is true. Most applications will not see any changes you make to their registry settings until the app is restarted. Most applications will, also, NOT expose any method to tell them that they need to reload their registry settings. Your best (read: most reliable) course of action is to stop the app and restart it.
|
|
|
|
|
If the changes are to a part that Explorer uses then just killing the Explorer process works as well, but please don't
Better inform the user that the changes will only apply after rebooting and letting him do it himself..
|
|
|
|
|
harold aptroot wrote: just killing the Explorer process
I tried to do this, but it only works in xp, vista OS.
On windows 2000 its not working, screen simply got blank if i kill the explorer ,
Any other help would be appreciated.
regards
|
|
|
|
|
Ok well it's a very bad thing to do anyway.. Standard practice is to ask whether to reboot now or later.
|
|
|
|
|
Hi,
In my application there is three ports listening, each have corresponding AsyncCallback method, ie 3 AsyncCallback method in the application. These three AsyncCallback methods are working as thread.These are ready to accept messages at any time.
How can i block or wait first and second AsyncCallback method while the third AsyncCallback methord is executing.
So after the execution of the third AsyncCallback method, next message in the queue is ready to execute, it can be in first , second or third AsyncCallback method.
Yhankyou
YPKI
|
|
|
|
|