|
PIEBALDconsult wrote: The world is going to end!
The world is going to \r\n!
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Ok, here is good question. I am building an application, which has a mainform, that opens a splash screen, shows a load progress bar, then jumps to the system tray. All of that is working fine. Now I am trying to implement some code that will allow me to insure that only one instance will open. I have done this successfully using a Mutex module and its WaitOne function. Now when the WaitOne function fails, i catch it with an else clause, which works, debugging shows it caught correctly, now I want to somehow tell the already open instance that someone tried to open you again, and to pop up a message balloon saying here i am. I have the following code, which sends a system message using PostMessage, and I have overridden the WndProc procedure in the MainForm, but the WndProc does not catch the message. I cannot figure out why. I know that the WndProc catches messages, because I tested it by inserting a thumbdrive, and the WM_DEVICECHANGED message was caught, but my custom message is no caught which leads me to beleive there is a problem with PostMessage, anyway here is my code
Mutex mutex = new Mutex(true, "MyProgram");
[STAThread]
static void Main()
{
if(mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
mutex.ReleaseMutex();
}
else
{
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST,
NativeMethods.ALREADYOPEN, IntPtr.Zero, IntPtr.Zero);
}
}
In the NativeMethods, HWND_BROADCAST is defined as 0xffff and the ALREADYOPEN message is defined with RegisterWindowsMessage("ALREADYOPEN")
then in the MainForm i have the following code
protected override void WndProc(ref Message m)
{
if(m.Msg == NativeMethods.ALREADYOPEN)
{
here is the code to show the BalloonToolTip, but this is never reached
}
base.WndProc(ref m);
}
In debug I can watch all the original creation messages being caught, and like I said the WM_DEVICECHANGED message is caught when I insert a thumb drive, but for some reason my custom message is not being caught, something has to be wrong in the PostMessage area I am thinking
Can anyone shed any light here?
|
|
|
|
|
Ok, i got i figured out, at least in my case. Instead of using PostMessage, I had to use SendNotifyMessage(IntPtr hwnd, IntPtr msg, IntPtr wparam, IntPtr lparam)
then just pass (IntPtr)0xffff as hwnd, and my custom msg as IntPtr, and IntPtr.Zero for both params and it works
|
|
|
|
|
I have a form1.cs and a formHelper class, so how can i show the relationship between form1 and formHelper class. Basically, the formHelper process the command which were invoked by the user. Also Can somebody demonstrate Association through code. Lets say, Class B has a Class A instance so how can i show in Visual studio 2005 class diagram.
Thanks
|
|
|
|
|
netJP12L,
You can create a diagram in VS by right clicking on your class in the solution viewer, and selecting "Create class diagram" (its something like that, cant remember exactly)
Regards,
Gareth.
|
|
|
|
|
Anyone have example of web service method for google language translation using http post method in asp.net using C# language or any idea of how to write it ?
|
|
|
|
|
If i've got the following code and its selecting the following values
C0603~A81_01
C0603~A81
how can i change it so that it splits these two values up
at the moment it is reading it as C0603~A81_01C0603~A81
thanks in advance
string roomcodeselect = "Select room_code from room_types where room_code like '" + room_code + "%' ORDER BY room_code DESC";
SqlCommand cmdroomcode2 = new SqlCommand(roomcodeselect, con2);
StringBuilder htmlStr_room_code5 = new StringBuilder("");
SqlDataReader readerroomcode = cmdroomcode2.ExecuteReader();
while (readerroomcode.Read())
{
htmlStr_room_code5.Append(readerroomcode["room_code"]);
}
lbtest2.Text = htmlStr_room_code5.ToString();
Session["sessiontest1"] = lbtest2.Text.ToString();
//string test2 = (string)Session["Sessiontest1"];
db = Session["sessiontest1"].ToString(); // "jh00~pr11_01";
if (db.Contains("_"))
{
string[] split = db.Split('_');
string s_number = split[1];
int i_number = Int32.Parse(s_number);
i_number++;
s_number = i_number.ToString("00");
db = split[0] + "_" + s_number;
}
|
|
|
|
|
I only gave a cursory glance, but the problem seems to be here: htmlStr_room_code5.Append(readerroomcode["room_code"]); You will have to add a statement that says htmlStr_room_code5.Append(Environment.NewLine); to your loop.
Having said that, there's a lot more to correct. Inline queries are frowned upon; I suggest you read up on Sql injection.
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
Like Virkram said, you are creating a string with all the values that match the LIKE statement. Either split each value returned, or use a WHERE room_code = 'value'; since im guessing room_code is unique, thus should only return 1 value.
Also, on a side note, maybe have a look @ http://msdn2.microsoft.com/en-us/library/ms229002.aspx[^].
Its ALOT easier to read code when you name objects with the camel/pascal naming convention eg: readerRoomCode instead of readerroomcode.
Regards,
Gareth.
|
|
|
|
|
Hi
I have a radiobutton list, how do i specify in the c# to enable disbable one of the items in the list
thanks
|
|
|
|
|
<br />
private void DisableRadioButton()<br />
{<br />
RadioButtonToDisable.Enabled = false;<br />
}<br />
now that wasn't too hard was it? Of course, you can go wild and actually pass a reference to the particular radio button you want to disable and disable that one.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
No your post disables the whole of the radiobuttonlist
I just want to disable one of the items in the list and I cannot find the correct syntax to do so
maybe you should read my original post again
|
|
|
|
|
sorted it myself:
RadioButtonList_audit.Items[0].Enabled = true;
thanks for all your wisdom
|
|
|
|
|
Actually, it only disables one, the one named "RadioButtonToDisable".
As is, the addendum to the post says that you can expand on it where you can pass a parameter so you can choose which one you want to disable.
so something like this could exist:
enum eRadioButtonList
{
RadioButton1 = 1,
RadioButton2 = 2,
RadioButton3 = 3
}
private void DisableRadioButton(eRadioButtonList rbl)
{
switch(rbl)
{
case 1:
RadioButton1.Enabled = false;
Break;
case 2:
RadioButton2.Enabled = false;
Break;
case 3:
RadioButton3.Enabled = false;
Break;
}
}
There, did your homework
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
ok i think im misunderstanding you or vice-versa
i had:
<asp:radiobuttonlist id="RadioButtonList_audit" runat="server" visible="false">
<listitem text="Default Audit Settings" value="defaultAudit" enabled="true/">
<listitem text="Create Audit History With Reasons For Changes" value="detailedAudit" />
</listitem></asp:radiobuttonlist>
i wanted to disable listitem text"Create Audit History With Reasons For Changes" etc...
i did
RadioButtonList_audit.Items[1].Enabled = false;
it worked.. problem solved
hmm......
|
|
|
|
|
Just an aside, but you should probably access the items through Id rather than by index (ie, give each listitem an id attribute, and use RadioButtonList_audit.Items["someId"].Enabled). That way, if you add or reorder the options later on, your code won't break. Note that I did not test the above, but only present it as a logical solution. The actual syntax of using the id may vary.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi! I need some help!!!
I have to store some datas(picture files)in the path and when harddisk is full i need to overwrite datas by replacing the old datas first!
How can i implement this program ??
thx
|
|
|
|
|
peaceziz wrote: i need to overwrite datas by replacing the old datas first
This automatically implies that you need some sort of mechanism that would maintain file creation order. My suggestion is that you ought to have a data table stored on a local database (SqlExpress is MORE than adequate) where you can retrieve the file names/paths in order and delete as necessary.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
i am using ASP.net, C# anD SQL Server2005,in the following query:
string q = "SELECT collapsed_building.b_name,collapsed_building.b_desc FROM collapsed_building WHERE collapsed_building.b_name LIKE '" + crimewithdate.text2 + "' ";
I WANT TO USE % AFTER THE KEYWORD like SO THAT ALL THE BUILDING NAMES WHICH MATCH THE VALUE ENTERED BY THE USER ARE DISPLAYED
WHEN I WRITE (LIKE '" + %crimewithdate.text2 %+ "'), IT GIVES ERROR, WHAT WILL BE THE CORRECT SENTAX
|
|
|
|
|
(LIKE '%" + crimewithdate.text2 + "%')
|
|
|
|
|
J4amieC wrote: (LIKE '%" + crimewithdate.text2 + "%')
Don't encourage SQL Injection Attackable code, please.
|
|
|
|
|
I didnt encourage it, I simply corrected his mistake. Frankly if the OP has this wrong then he's going to be bafffled by terms that he doesnt understand.
Im 100% with you on the Sql Injection thing, but there is learning to walk before one can run.
|
|
|
|
|
J4amieC wrote: there is learning to walk before one can run.
I teach a basic C# training course. I actually threw out the materials I'd been given on the subject of databases and rewrote it. I ensure that at no time is anyone encouraged to inject values and I go directly to parameterised queries. So far with good results.
However, you might be right. If they already have the bad habit it might make it more difficult to break.
|
|
|
|
|
|
Im glad it worked. Now please heed the warnings below about Sql Injection attacks. IT IS IMPORTANT!
|
|
|
|