|
You're reading the wrong examples. Use either readonly fields
public readonly int Hours ;
or readonly properties
private int hours ;
public int Hours { get { return hours ; } }
|
|
|
|
|
Ooohhhh.... tasty.
Damn these C# books! I suppose they were really just telling me to control access to the fields, but still... can't they assume I'm relatively dumb?
[modified] Forgot to say "thanks". Thanks!
|
|
|
|
|
"C# For Dummies" is good.
|
|
|
|
|
Actually, I have to say: I hated that one. The hoaky tip titles and non-programming content just drove me crazy.
Microsoft Visual C#2005: Step by Step is pretty good, but it limits itself. The writing, though, is very clear.
|
|
|
|
|
JoeRip wrote: Is there a way to implement a "read only" struct whose fields are directly readable but not writable?
Just to add to what PIEBALDconsult said. It sounds like what you are wanting to do is create an "immutable" object (unless you have some other mechanism where you update the fields). An immutable object is one that once created does not change. Typically, if you want to change an immutable object you just create a new one.
Strings are an example of immutable objects. If you create a string then call something like ToUpper() on it you get back a new string. The original string is not changed.
(Just to add to your vocabulary)
|
|
|
|
|
I always get this exception -- System.Data.OracleClient.OracleException: ORA-00911: invalid character at System.Data.OracleClient... which indicates the connection is not valid.
Following is my code:
string connectionString = "Data Source=ora01;User ID=zd01;password=1234;Persist Security Info=True;";
OracleConnection con = new OracleConnection(connectionString);
con.Open();
string sql = "insert into ua_user values(4, 'vivien', 'vivien', 9);";
OracleCommand command = new OracleCommand(sql, con);
command.ExecuteNonQuery();
con.Close();
the sql command is working, and this worked under .net 1.1, now I am writing under .net 2.0, it seems refuse to work.
Can anyone tell me what I did wrong, thank you in advance.
|
|
|
|
|
I have a form that takes a file with like 1800 students and adds them to active directory. I think I have the backgroundworker working, but I want to update the form with each name added. I see how to use progresschange to update a progress bar, but I can't seem to pass messages.
I tried some sort of thread creation with invoking, but I still don't see how I pass the message to that thread.
Any ideas or a link to good tutorial? the ones I find only deal with passing integers with updateprogress.
Thanks
|
|
|
|
|
|
I read the following article on how to draw the contents of an application screen to a bitmap. I am wondering if there is any way to get this to work if the screen is minimized? I would like to do a screen capture of a minimized window, if possible. Does anyone have some ideas as to how I can do this? Thanks,
http://www.codeproject.com/csharp/screen_capturing.asp[^]
Jeff
|
|
|
|
|
Hi Jeff!
I have not yet read that article, it's on my todo list.
An application is or can be aware it is minimized, since it is getting Resize events
(with zero width and height), so chances are it will refuse to paint anything as long as
it is minimized.
So my best guess is restore it to normal size, move it outside the regular screen area
if you don't want to see it (say Location=-30000,-30000), use Control.DrawToBitmap on the
Form, then restore location and state.
I am not sure you can set location before leaving minimized state to avoid a glitch though.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello, Im having difficulties with a button with hover text.
I have a standard button that I created a hover event for.
this.gpsInfo.MouseHover += new System.EventHandler(this.gpsInfo_MouseHover);
then i create a tooltip
private void gpsInfo_MouseHover(object sender, EventArgs e)
{
tp = new ToolTip();
tp.Show("GPS Information", gpsInfo);
}
For some stupid reason, the message shows up more than once. So I tried other events like mouse cursor change, when your over the button. And then call the tooltip when the cursor changes, but that doesnt work at all.
Help............... Do I have to go graphics..
|
|
|
|
|
I hate to say use the wizard but if you add a tooltip to the form and then select the given tooltip from the controls properties window it should work nicely.
The end result is:
Create a member: private System.Windows.Forms.ToolTip toolTip1;
In init:
this.toolTip1.SetToolTip(this.button1, "Rwar");
It should work automatically.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
funny enough, i did that a few minutes ago and it worked. But I may take you up on contractor work. Contact me at j_sen21@hotmail.com
|
|
|
|
|
j_sen wrote: For some stupid reason, the message shows up more than once
Maybe because someone felt it necessary to create a new tooltip every time MouseHover fires?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
They can be found here:
http://www.codeplex.com/3DTools
Basically there's some problems with using events i can't figure out and i need someone more skilled to figure this out and explain perhaps too.
I added
to
Visual2's first StackPanel in Channel9Demo(appears right above the text box)
and it fires up on middle mouse button and right mouse button but no left mouse button(the button animation still shows beeing pressed by left mouse button though). The other mouse events don't seem to fire up at all. Anyone knows how to work with mouse events using Tools3D? I even tried removing the trackball that works with left mouse button but it didn't change anything. I am wondering too if other events wouldn't work and why. What is the correct approach on this?
|
|
|
|
|
Hi all,
I would like to know how to go about embedding an Excel spreadsheet into a
c# Windows forms application.
Any tips or pointers to some articles to get me started would be much appreciated.
Thanks for your help
kort
|
|
|
|
|
I have defined a user Exception class. The exception will be thrown in
public int GetNextInt()<br />
{<br />
return Int32.Parse(GetNextToken());<br />
}<br />
GetNextToken() reads a file stream, pulling characters until a predefined delimiters are met (space, end of line, etc) returning the string. I can not change anything in GetNextToken.
If GetNextToken does not return an int value I would like to throw my user defined exception. I have been unable to do so. As soon as as Int32.Parse() finds the input string is not an int it throws an exception.
Is there a way I can throw my user defined exception or use the data field in the predefined exception to add information.
Thanks
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
If I were you, I would use Int.TryParse to check if the input string represents a number
|
|
|
|
|
public int GetNextInt()
{
int parsedValue;
bool success = int.TryParse(GetNextToken(), out parsedValue);
if(!success)
{
throw MySuperSpecialException(...);
}
return parsedValue;
}
|
|
|
|
|
public static bool TryParse(string s, out int result);
Int32 myint;
if(!Int32.TryParse(",", out myint))
throw new YourCustomException();
return myint;
|
|
|
|
|
A SUPER special exception? Must be some important error to get that kind of treatment.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
The original OP wanted to throw their own custom exception...Personally, I prefer to call them all "ABone" and let future maintenance developers sort it out
EDIT: Or even "AFrikinBone" if you like sharks with lasers...
|
|
|
|
|
The answer is to use Int32.TryParse() .
Modified
Thanks to all for your answers.
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
If you need to know what the actual exception was...
public int GetNextInt()
{
try
{
return System.Int32.Parse(GetNextToken());
}
catch ( System.Exception err )
{
throw new MyException ( "blah blah blah" , err ) ;
}
}
|
|
|
|
|
Now, i said i would, so i will http://www.codeproject.com/lounge.asp?msg=2309375#xx2309375xx[^]
Your Majesty,
I have been unable to obtain the icon of an open window for some time, despite my toughest efforts. I have been using SendMessage to send a message to a window, notepad for example, with the message WM_GETICON, and trying to get both small and large icons. This always returns with 0. Ma'am, i would greatly appreciate it if you would help me in solving my dilemma, through use of SendMessage or otherwise. Below you will find an example of the code i am using.
I remain your faithful and humble subject,
The Undefeated
hWnd = IntPtr.Zero;
foreach(Process window in Process.GetProcesses()) {
if(window.MainWindowTitle == this.textBox1.Text)
hWnd = window.MainWindowHandle;
}
if(hWnd == IntPtr.Zero)
MessageBox.Show("Could not find window");
...
if(hWnd != IntPtr.Zero) {
int hIcon = SendMessage(hWnd, 0x7f, 1, 0);
if(hIcon == 0)
MessageBox.Show("Damn, it did it again");
else
this.pictureBox1.Image = Bitmap.FromHicon(new IntPtr(hIcon));
}
Wow, writing my user name "The Undefeated" ugh, its so old. I havn't used it in years, many years, but i thought i should perhaps leave it alone anyway
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|