|
|
CreateGraphics() is e mthod available from the Control class. So writing myControl.CreateGraphics whill create the appropriate Graphics object for you. Another hint: Dont forget disposing it when you don't need it anymore:
using (Graphics g = myControl.CreateGraphics()) {
}
|
|
|
|
|
I am new to C# and am doing a project using winforms.
Right now I have all individual forms (say 12 forms) for carrying out each user functionalities with proper navigation. Every thing works well. But now I want create a master form and keep all the 12 form as child forms. How do I do it.
Also even after I close the project I could still see my .exe process still running in the task manager. how do I solve this.
Thanks in advance.
|
|
|
|
|
Ann66 wrote:
But now I want create a master form and keep all the 12 form as child forms. How do I do it.
The form that gets started when you start your app should be the master form. Then it creates the child forms and uses ShowDialog to make them appear.
Ann66 wrote:
Also even after I close the project I could still see my .exe process still running in the task manager. how do I solve this.
For how long ? That just plain should not happen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi All,
I'm new and trying to get cell values from a datagrid. The grid itself is read only so a double_click event or context menu selection is required on a given row to call an edit form. I can get the row selected easily enough, but can't seem to get to cell values? I thought this would be a simple datagrid1[row,cell] call. Searching the net shows lots of advanced examples using different control types in each cell and doing all sorts of stuff. I don't need to do all sorts of stuff, just a simple selection of the cell values for a given row. I'm missing something thats probably obvious because this is far from complex.
How do I execute this simple functionality?
TIA
|
|
|
|
|
never mind, got it. it was as simple as [row,col]
thanks
|
|
|
|
|
Compiling my code, I got this error:
Error 1 Inconsistent accessibility: parameter type 'Asterisk2.Extension' is less accessible than method 'Asterisk2.ExtensionForm.AddExtension(Asterisk2.Extension)'
in the class ExtensionForm.cs
For thelife of me, I cannot figure this one out.
Any suggestions?
Lilli
|
|
|
|
|
Well, this could happen if you have something like this:
private Extension {...}
public ExtensionForm
{
public AddExtension(Extension myExt) {...}
}
See, if AddExtension is public, then it can be called by anybody. But since it expects an Extension parameter, which is private, nobody can actually call it then except for you. Does that help?
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Yeah, that was my first guess but Extension.cs is public as well. They also share the same namespace.
|
|
|
|
|
Would you mind posting the signatures of all the classes, namespaces, and methods involved? I think it would be helpful to determine the error.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
namespace Asterisk2
{
public partial class ExtensionForm : Form
{
public void AddExtension(Extension e)
{
...
}
}
}
namespace Asterisk2
{
class Extension
{
public Extension(string ext)
{
....
}
}
}
Thanks so much!
Lilli
|
|
|
|
|
AddExtension is public, but Extension is not . Declaring Extension to be public should solve your problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yeah, Senthil already answered it. Basically, you've got Extension declared as class Extensions . When the compiler sees that, it treats it as a private class. You have to explicitly add the public keyword to it to make the class public.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
I am fairly new to C# and was wondering if there are any available methods to search for text in a given file. i.e in a file that has the following format:
Artist: U2
Album: Joshua Tree
Year: 1983
Song: Where the Streets have no name
Are there any available methods that would allow for the extraction of the relevant information into the relevant tags?
Kind Regards
|
|
|
|
|
Since the file is plain text you can use a simple text reader to read the file. Lets say you wanted to parse out all of the lines given into some respective parameters. You would first create a class file that can hold of of the attributes: (I'm writing all of this in the browser, not in a C# compiler so there may be some syntax mistakes...)
<code>
public class MyFile
{
private string artist;
private string album;
private string year;
private string song;
public MyFile()
{
}
public string Artist
{
get
{
return this.artist;
}
set
{
this.artist = value;
}
}
public string Album
{
get
{
return this.album;
}
set
{
this.album = value;
}
}
public string Year
{
get
{
return this.year;
}
set
{
this.year = value;
}
}
public string Song
{
get
{
return this.song;
}
set
{
this.song = value;
}
}
}
</code>
Once you have this class you can read the file using a TextReader:
<code>
System.IO.TextReader reader = new System.IO.TextReader(Application.StartupPath + "\\myfile.txt");
try
{
MyFile customClass = new MyFile();
while(true)
{
string line = reader.ReadLine();
if(line == null)
{
break;
}
ParseText(line,ref customClass);
}
}
finally
{
if(reader != null)
{
reader.Close();
}
}
The ParseText method would look something like this:
<code>
public void ParseText(string text, ref MyFile customClass)
{
if(customClass == null)
{
customClass = new MyFile();
}
if(text.IndexOf(":") > -1)
{
string[] temp = text.Split(':');
if(temp.Length > 1)
{
select(temp[0].Trim().ToLower())
{
case "artist":
customClass.Artist = temp[1];
break;
case "album":
break;
customClass.Album = temp[1];
case "year":
break;
customClass.Year = temp[1];
case "song":
break;
customClass.Song = temp[1];
}
}
}
}
I think that should about do it. Like I said, remember I typed this all in the browser window, so there could be some syntax errors. Try this out and let me know how it goes.
|
|
|
|
|
That code is pretty brittle. If your file format changes at all, it's going to be shot. My recommendation would be to learn about Regular Expressions and use that to parse out the file.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
I was giving him code for his specific need. He is obviously new and by the looks of it only wants to do this for one small item. That's why I didn't recommend anything too difficult. You can "what if" yourself in the programming world to a 5 year project that would only take 5 minutes if you're coding for a specific need...
Also, changing this "file format" won't cause the code to error out, it may cause some undesirable results, but then again even with RegEx you can create undesirable results if you're just TRYING to break it.
|
|
|
|
|
Good point. I guess I just assume that everybody should know about RegEx.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
I don't know about you, but RegEx was the most confusing crap in the dev world for me to learn
|
|
|
|
|
Really? I found RegEx to be quite easy. I guess it helps to have a good tool like Expresso or The Regulator to play with on some sample data.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Yeah.. learning the RegEx I guess wasn't that difficult... it's remember all of the syntax that's a pain to me
|
|
|
|
|
Thanks so much for your help. I have managed to create a project and fixed a few errors. However I keep having a problem with this line:
ParseText(line,ref customClass);
Getting this error:
D:\Documents and Settings\Alvin\My Documents\Visual Studio Projects\File Searcher\Form1.cs(113): An object reference is required for the nonstatic field, method, or property 'File_Searcher.Form1.ParseText(string, ref File_Searcher.MyFile)'
Would really appreciate your help!
Kind Regards
|
|
|
|
|
Wherever you are declaring the object File_Searcher.MyFile you must instantiate it. Example:
File_Searcher.MyFile myFile = new File_Searcher.MyFile();
then on the line use: File_Searcher.Form1.ParseText(string, ref myFile)
|
|
|
|
|
Hi
I am working with Crystal reports XI. Dynamic Image location is
possible in CR XI... But I couldnt understand teh example given for
dyanmic image location in businessobjects.com...
so please anyone witha small example explain to me how to do it using
c#.
dhol
|
|
|
|
|
Hi all,
I am a beginner in c#. I had used the following code to draw a line as given in the documentation. Line doesn't appear. Am I missing something or is it a painting text problem during refreshing. this code is executed as a part of a handler for a menu item..
<br />
<br />
Line myLine = new Line();<br />
myLine.Stroke = Brushes.Black;<br />
myLine.StrokeThickness = 10;<br />
myLine.StrokeStartLineCap = PenLineCap.Round;<br />
myLine.StrokeEndLineCap = PenLineCap.Round;<br />
myLine.X1 = 10;<br />
myLine.Y1 = 10;<br />
myLine.X2 = 75;<br />
myLine.Y2 = 90;<br />
<br />
Kindly throw light on this..
Thanks,
|
|
|
|