|
Your code should look like this
string dbPath = @"C:\D B\" //escape
|
|
|
|
|
Hello, thanks for replying. I already have it like that. It reads in the entire path, and it does connect to the datasource, but when it comes to reading in the Data with the datareader, it doesn't do it. But when I change the directory manually back to C:\DB and the dbPath = @"C:\DB\", it works.
Sincerely,
The Major Rager
|
|
|
|
|
Why does this crash on invalid text? Otherwise it works, but if user input is invalid I end up in a MessageBox "house of mirrors"...
THanks a lot! -> Here's the code....
//////////////////////
////////////////////
void DrawComplexNumber1(Graphics g)
{
Pen p = c_xy.GetNextPen();
p.DashStyle = DashStyle.Dot;
c_xy.SetOrigin(xIndent + graphRect.Width/2, yIndent + graphRect.Y/2);
try
{
cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text);
}
catch
{
MessageBox.Show("Error!");
}
try
{
cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text);
}
catch
{
MessageBox.Show("Error!");
}
g.DrawLine(p, 250, 250, (float)(250 + (xIndent * cmplxValue1.Real)), (float)(250 - (yIndent * cmplxValue1.Imaginary)));
}
///////////////////
private void complex_1OK_Click_1(object sender, System.EventArgs e)
{
drawLine1 = !drawLine1;
Invalidate();
}
///////////////////////////
//In the Paint Handler
if(drawLine1)
DrawComplexNumber1(e.Graphics);
|
|
|
|
|
Validate the data outside of the paint handler.
Now you are showing messageboxes from inside the paint handler, and when you klick away the messagebox it will cause a redraw of part of the screen, which most likely causes a new paint event in your application. This will put you into an infinite loop.
---
b { font-weight: normal; }
|
|
|
|
|
How can I create and display a form to be topmost to the application only?
The requirements are :
* The form is the topmost window of the application.
* The form should not be topmost to other application and desktop. If the application is not the active application, the form window should not be displayed above the current application.
*The form should be in modeless status. The user can work with the application while the topmost form window is displayed.
A word in simple way, how to create a window like the "Find" dialog in the notepad.exe?
The topmost property in the form class can not work. If it is set to be true, the window will be topmost of everything.
Any expert has some idea? Or provide any clue to a windows API?
Thanks,
leo
|
|
|
|
|
Create the dialog and display it using Show (instead of ShowDialog ). Set it's Owner property to your main form.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
|
If its on mute, i want to unmute it, if its too quiet, i want to turn it up, if its too loud then i want to turn it down, etc.
Any ideas?
|
|
|
|
|
I've never worked with multithreading before in any language.
I'm trying to figure out how to do the following:
I have a function, which generates unique values based on the current time.
It saves the data to a log file.
I have it set that when I click a button, it executes this code.
Rather, what I need to happen is to have it continually execute the function every 60 seconds until I reclick the same button.
I assume I need to use threads to do this. I've looked up several tutorials, but I really can't find an example to do this.
Can someone give me an idea?
Thanks.
|
|
|
|
|
... this is the function I have. The first if clause needs to start a thread which executes the SaveWindow function every 60 seconds. The second needs to terminate the thread. I don't even know if this is the way threads work.
private void buttonScraperControl_Click(object sender, EventArgs e)
{
if (buttonScraperControl.Text == "Start")
{
buttonScraperControl.Text = "Stop";
SaveWindow(); // EXECUTE THIS FUNCTION EVERY 60 SECONDS
}
else if (buttonScraperControl.Text == "Stop")
{
buttonScraperControl.Text = "Start";
// STOP FROM EXECUTING EVERY 60 SECONDS
}
}
|
|
|
|
|
I believe you can use the built in "Timer" control. http://www.c-sharpcorner.com/controls/timer.asp
|
|
|
|
|
Will the timer stop execution of other parts of the program?
There are several other things that the user will be doing while
this bit of code is executing.
Is a timer really the correct solution?
Thanks!
|
|
|
|
|
If you use a timer, it will be using a single thread. That means that the timer will only be triggered when your program is not busy doing anything else.
If you use a separate thread, it will be running even if your program is busy. The drawback is that the code has to be thread safe, meaning that if you are using any variables from both threads, you will have to take special precausions to make sure that only one thread at a time is using the variables.
---
b { font-weight: normal; }
|
|
|
|
|
The System.Form.Timer or whatever it is, for some reason deson't lock up your GUI. Someone once explained why to me...
/\ |_ E X E GG
|
|
|
|
|
I think a timer would be a good solution for your problem, cause it was made to execute code in regular intervals. Now you have to select the right timer for your needs.
If you use the System.Windows.Forms.Timer , your code will be executed in the UI thread. This prevents you from paying attention to threading issues, but if the code is time-consuming it will hang your GUI, cause the UI thread is busy.
If you use System.Timers.Timer or the System.Threading.Timer , your code will be executed by a worker thread. This won't affect your GUI, but you have to pay attention to threading issues e.g. change of GUI controls.
Take a look at this site[^] on MSDN for some more information.
www.troschuetz.de
|
|
|
|
|
Hi,
I would like to create a winform application using c#, that looks kind of like Adobe Photoshop. That means the main window will have some small dockable windows inside the main window (those dockable windows can be minimized, closed, or maximized and docked). These windows will have other controls inside them.
I was wondering if you can give me some pointers on how to create windows like that, or can you send me links to some custom controls that I can use in my code that behave like those windows.
I'm still using visual studio.NET 2003, I might switch to VS.NET 2005 if there are controls like that in VS2005. Any idea, pointer, links, codes will be much appreciated.
Thanks
Ben
|
|
|
|
|
What you are describing is MDI forms. Try looking here: http://www.codeproject.com/csharp/mdiformstutorial.asp
-- modified at 18:00 Thursday 13th October, 2005 (typo'd)
|
|
|
|
|
Not really. I want the forms to be dockable too.
|
|
|
|
|
Did you know that the Form class derives from Control? Think about that. A Form can be used just like a control. All it takes is a couple of modifications to it's properties. Check out this[^] article on MSDN for more information.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
I am working on a program to display "flash cards." Basically, the flash cards are 2 jpeg files, the front and the back. I'm using them to aid in learning a foreign language. Currently, I have this code:
private void btAdd_Click(object sender, EventArgs e)<br />
{<br />
hpClass blah = new hpClass();<br />
blah.addToArray( tbFrontFile.Text, tbBackFile.Text );<br />
blah.serializeArray( blah, "test.txt" );<br />
}<br />
[Serializable]<br />
public class hpClass<br />
{<br />
Stream[,] images;<br />
FileStream fsFront;<br />
FileStream fsBack;<br />
FileStream fsData;<br />
<br />
BinaryFormatter bfSerial;<br />
<br />
public void addToArray(string front, string back)<br />
{<br />
fsFront = new FileStream( front, FileMode.Open );<br />
fsBack = new FileStream( back, FileMode.Open );<br />
<br />
images = new Stream[1, 2]<br />
{<br />
{ fsFront, fsBack }<br />
};<br />
}<br />
<br />
public void serializeArray(object anything, string path)<br />
{<br />
fsData = new FileStream( path, FileMode.Create );<br />
bfSerial = new BinaryFormatter();<br />
bfSerial.Serialize( fsData, anything );<br />
fsData.Close();<br />
}<br />
}
The error I am getting is this:
Type 'System.IO.FileStream' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
And the bfSerial.Serialize line is the one generating the error. I'm using the C# 2005 Express Edition Beta. I'm completely lost Any suggestions?
|
|
|
|
|
Every member of your class needs to be serializable or marked with [NonSerialized]. You cannot serialize streams, so they'll need the [NonSerialized] attribute for sure. If you really want your object to contain the binary content of all those files, you should read the data into byte array members probably. However, that sounds clunky, especially if the jpg files are right there, all your object needs to remember is their names, right? Let me know if I'm not understanding your question right.
Matt Gerrans
-- modified at 17:26 Thursday 13th October, 2005
|
|
|
|
|
Actually, I plan to use the file that is outputted as flashcard sets. Meaning it should contain all the information as the original jpegs and also on how to display them. This way, I won't have to distribute (to my friends) hundreds of jpeg files which could get moved, deleted, etc. This is why I wanted to stream the contents of the jpeg file into an array, and then save the array to a file.ext. I didn't realize you couldn't serialize streams :p So I guess I would have to dump the data into a byte array. You're right, it does sound a little clunky. I was thinking of using zip files, but then they wouldn't necesarrily come out in the right pairs (front and back.) This is the only other option I could think of.
Thanks for your input
|
|
|
|
|
Hi
I have a general question regarding validation of an objects attributes. I am working on a web application and involved in developing the business layer code. Given the fact that I am relatively new to web development, I had this question: Do I do the validation of the object's attributes before doing any action in the business layer? For example, if I have an user class in my business layer with 5 attributes, and some methods like select, delete, insert, update etc which are instance methods. So, before inserting the actual user into the database, do I need to write validation code in the insertmethod to see if the 5 attributes are not null? I am not sure if this needs to be done at the presentation layer or the business layer.
Any comments please?
Thanks
|
|
|
|
|
Probably you should have your validations on three levels. Each has its own purpose:
1. Validate on the user interface, to provide a speedy answer to the user, and to avoid hitting the server unnecessarily. This may not include all the validations, only those that are quick and simple to do on the UI layer.
2. Validate on the business rules layer, to enforce the business rules. This includes all rules, with the possible exception of referential integrity, that can be delegated to the database server. Here you can call any method and do the most complicated validations.
3. Validate on the database server. The objective is to enforce a minimum sanity on the data, like required fields and referential integrity. Theoretically all validation could be done here, using constraints, stored procedures and triggers, but I think it is more productive to use Visual Studio for coding logic. If you can be sure all database access will be through your code, you can keep the validation at this level simple. Anyway, this layer of validation is a safety net.
Good luck.
Fernando Correia
|
|
|
|
|