|
Thank you for your reply Peter but I am unsure of how to go about using args[1] to retrieve the filename... Can you please explain in a little more detail?
thanks again
|
|
|
|
|
Sorry Pete but you are wrong. args[0] is indeed the first argument.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Thanks for that - I guess I'm getting my C++ and C# mixed up (C/C++ use args[0] for the program name).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
To be honest, I checked because I couldn't remember. It just meant the Lucky Luc stole the medal!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
In your defense, MS organized the confusion by defining Environment.GetCommandLineArgs() in the old way: "The first element in the array contains the file name of the executing program. If the file name is not available, the first element is equal to String.Empty. The remaining elements contain any additional tokens entered on the command line."
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.
|
|
|
|
|
Only in C(++). In any .net application, args[0] is the first argument passed
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Huh?
you managed to get the content of the file you're interested in, but you don't know how to get its name??
args[0] is holding the one or first file of interest if:
- you created a desktop shortcut with target myFantasticExeFile "%1"
- or you told Windows to open a specific file extension with your app
BTW: it is strange to me you have an editor form that you need to feed from the outside; it seems much more logical to me to give it a public void Load(string filename) method so setting the tab's text, and interpreting the file's content (RTF/plain text) is burried inside the editor.
[ADDED] if the problem is extracting the short file name from the entire file path, have a look at the System.IO.Path class
[/ADDED]
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.
modified on Wednesday, June 3, 2009 10:13 AM
|
|
|
|
|
Damned you Mr P! Too fast for me!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I gave you a 15-minute head start. Not enough?
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.
|
|
|
|
|
Obviously not.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
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.
|
|
|
|