|
Hi,
I have 5 CheckedListBox controls on a winForm. I am appending the selected items in a stringBuilder on a buttonClick Event. my question is,
say,
I have checkedListBox named as A, B, C, D and E. after selecting the items from each CheckedListBox, it first shows me the selected values from E,D,C,B and A. why does it shows the selection in reverse, when i am adding the selected values immediately to the StringBuilder. my code is given below.
Thanks, for ur help. I am actually using the selected items to form a dynamic query.
StringBuffer sb=new StringBuffer();
CheckedListBox clb = null;
foreach(Control c in groupBox1.Controls)
{
if(c is CheckedListBox)
{
clb = c as CheckedListBox;
if(clb.CheckedItems.Count !=0)
{
for(int i=0; i<=clb.CheckedItems.Count -1; i++)
{
sb.Append(clb.CheckedItems[i].ToString());
sb.Append(", ");
}
}
}
MessageBox.Show(sb.ToString());
abhi
|
|
|
|
|
Hi Abhi,
Take a look in your form's InitializeComponent() method. Somewhere in there, the VS designer wrote you some code like:
groupBox1.Controls.Add(this.CheckedListBoxE);
groupBox1.Controls.Add(this.CheckedListBoxD);
...
The items appear in the Controls collection in the order in which they were added (AFAIK). So either: edit the InitializeComponent() code to reverse the order in which they are added, or just reverse your loop and work for the end of the collection forward. I'd do the former, but I don't think there's a compelling argument either way.
Hope this helps,
Bill
|
|
|
|
|
Because .NET have added them to group in that order.
Look into InitializeComponent method
You would see something like
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkedListBox4);
this.groupBox1.Controls.Add(this.checkedListBox3);
this.groupBox1.Controls.Add(this.checkedListBox2);
this.groupBox1.Controls.Add(this.checkedListBox1);
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
I'm normally a C++ .NET programmer but have been working on a C# .NET DirectX project. Everything works fine for me, but when I try to give the executable and needed data files to friends, they all end up with errors that won't let the program load (all have the latest version of DirectX and .NET framework).
At least one error I have seen is "Failed to delay load library mscorlib.dll (win32 error:998)"
Am I missing something with how I compile my project? Any suggestions would be appreciated.
Thanks
Cyric
cyric74@hotmail.com
|
|
|
|
|
I believe I was reading some DX documentatin which said this was a possible problem with DirectX. I could be wrong. Do you set the project to make a local copy of anything you import ? I always do that, and then anything I use goes with the distribution.
Did you use DX to play audio and video ? If so, how did you find it ? I'm preparing an article on all the problems I had with it, so I wondered if anyone else has found it the same.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How do I set the project to make a local copy of the imports? I guess there is a difference with C++ .NET and C# .NET because I've never run into a problem like this with C++. It always packaged everything it needed without my messing around with it.
I have not yet used DX for audio/video. It is only being used graphically in this project at the moment.
|
|
|
|
|
Click on the reference in question and in the properties box is 'Copy Local'. Set this to true.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I've just about finished my project, and I'm trying to set up the icon. As you can imagine, a google for
'icon' is next to useless. I've edited the icon in VS, and it appears in 32x32, but I can't see how to set the 16x16 icon ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
With the icon open, click Image -> Current Icon Image Types and select the size you want. Under the Image menu is additional actions.
Note, I do recommend you use a decent icon creation package. I personally like Icon Workshop, but I'm not recommending anything.
Also, with .NET applications make sure that your main form's Icon property is set as well as the project's icon in the project properties.
Personally, to save room, I embed the icon you'll use for Form.Icon and define a static property to return that Icon . In your form's constructor, set this.Icon to the Icon returned from said property, and you can reuse it as well. If you use the PropertyGrid, the icon is base64-encoded and serialized to a ResX file specific to the Form . Using that in additional forms or controls will do the same for a different ResX file.
Note that the project setting actually embeds the icon as a Win32 resource. The command-line switch that's equivalent is /win32icon:<file>.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks for the help. This was more info than I'd managed to work out on my own.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
All sorted.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Prohibiting multiple instances is not the problem neither is restoring the app if it is just minimized on the task bar but when its in the system tray and hidden i'm really pulling my hair out as to how to restore it.
Thanks in advance for any thoughts
|
|
|
|
|
Set WindowState to FormWindowState.Normal or FormWindowState.Maximize and, optionally, call Show to make sure that the form is visible (if you simply set Visible to false or call Hide on the form).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Sorry my fault for being unclear. yes that would be the case if i just wanted to double click the icon and restore it but what im looking for is restoring the previous instance which is in the system tray when another instance is started.
|
|
|
|
|
Yes, and what I said still applies. What you need to do, though, is get an instance of the Form that is your main application window. Yes, the HWND may be 0, but there's still a Form instance.
This is where .NET Remoting comes in handy. Read Accessing Objects in Other Application Domains Using .NET Remoting[^].
You could also use COM monikers, but there's a lot of overhead involved with interoping the necessary COM interfaces and functions. .NET Remoting is much easier to implement and provides you better access to your managed application.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Dionne wrote:
its in the system tray and hidden i'm really pulling my hair out as to how to restore it.
If you have the Handle to the window, you can call ShowWindow to cause your window to become visible. The P/Invoke signature looks like this:
const UInt32 SW_HIDE = 0 ;
const UInt32 SW_SHOWNORMAL = 1 ;
const UInt32 SW_NORMAL = 1 ;
const UInt32 SW_SHOWMINIMIZED = 2 ;
const UInt32 SW_SHOWMAXIMIZED = 3 ;
const UInt32 SW_MAXIMIZE = 3 ;
const UInt32 SW_SHOWNOACTIVATE = 4 ;
const UInt32 SW_SHOW = 5 ;
const UInt32 SW_MINIMIZE = 6 ;
const UInt32 SW_SHOWMINNOACTIVE = 7 ;
const UInt32 SW_SHOWNA = 8 ;
const UInt32 SW_RESTORE = 9 ;
const UInt32 SW_SHOWDEFAULT = 10 ;
const UInt32 SW_FORCEMINIMIZE = 11 ;
const UInt32 SW_MAX = 11 ;
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks Nick thats very close but the only problem left is that the Handle that ShowWindow is looking for is the MainWindowHandle and when an app is minimized to the system tray and hidden the MainWindowHandle is 0.
|
|
|
|
|
Dionne wrote:
but the only problem left is that the Handle that ShowWindow is looking for is the MainWindowHandle and when an app is minimized to the system tray and hidden the MainWindowHandle is 0.
That doesn't make any sense, the Handle or HWND for the application doesn't get set to 0 when the application is minimized and hidden. You can prove this simply by the following, you will see the Handle is still there:
using System;
using System.Timers;
using System.Drawing;
using System.Windows.Forms;
public class test : System.Windows.Forms.Form
{
Button b;
System.Timers.Timer t;
public test()
{
InitializeComponents();
}
public void InitializeComponents()
{
b = new Button();
b.Text = "Hide Me";
b.Click += new EventHandler(bClick);
t = new System.Timers.Timer();
t.Elapsed += new ElapsedEventHandler(elapsed);
t.Interval = 3000;
t.Enabled = true;
this.Controls.AddRange(new Control[] {b});
}
private void bClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
}
private void elapsed(object source, ElapsedEventArgs e)
{
MessageBox.Show(this.Handle.ToString());
}
[STAThread]
public static void Main()
{
Application.Run(new test());
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Yes that makes perfect sense
[STAThread]
static void Main()
{
string strSystemMutex = Process.GetCurrentProcess().ProcessName;
bool firstInstance;
Mutex mut = new Mutex(true, strSystemMutex,out firstInstance);
if (firstInstance)
{
try
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
catch {}
finally
{
mut.ReleaseMutex();
}
}
else
{
try
{
Process[] processes =
Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
foreach (Process proc in processes)
{
if (proc.Id != Process.GetCurrentProcess().Id)
{
WinMSG.ShowWindow(proc.Handle,3);
System.Environment.Exit(0);
}
}
}
catch{}
}
}
try this your test and run a multiple instance you'll see what i mean. proc.Handle is not the right parameter and proc.MainWindowHandle is 0
|
|
|
|
|
You might want to take a look at this article[^] by Chris Anderson.
From my experience the next thing you'll want is to delegate commandline options to the running instance, and that's something that can be achieved really easily using the ApplicationFramework provided by Chris.
A few little caveats, though:
When using .NET 1.1 you'll have to modify the code to include the required typeFilterLevel property for the channel used or else you'll get security exceptions.
You should add an InitializeLifetimeService() override returning null or else you won't be able to activate your previous instance after 2 minutes.
If you plan to use remoting in your application yourself you should remove the channel property bindTo = "127.0.0.1" (all three in UserApplicationContext.cs) or you'll get strange errors when handling remote events.
Regards,
mav
|
|
|
|
|
hi,
now i am devloping an report using crystal report in my application. i need to print in preprinted sheet. i need to set fixed width for details section and after the fixed size then print goes to next new page. any one help to me.
thanks in advance
Have A Nice Day!
Murali.M
|
|
|
|
|
Hi,
I have a WindowsForm, which has a groupBox and has multiple CheckedListBox Controls. I want to clear all selected check items dynamically, instead of doing it individually. I want to get all the controls from the groupBox first, which also has other controls, then get the CheckedListBox controls and clearing it, if selected.
I wrote this code, but it is not working, its not coming out of the loop. Any help, will be really appreciated.
foreach(Control ctrl in this.groupBox1.Controls)
{
if(ctrl is CheckedListBox)
{
CheckedListBox cb=(CheckedListBox)ctrl;
for(int i=0; i<=(cb.CheckedItems.Count-1); i++)
{
cb.ClearSelected();
}
}
}
abhi
|
|
|
|
|
Hmm, that is rather strange. Here is a quick work around.
private void ClearSelected()
{
CheckedListBox clb = null;
foreach(Control c in grp.Controls)
{
if(c is CheckedListBox)
{
clb = c as CheckedListBox;
if(clb != null)
{
foreach(int index in clb.CheckedIndices)
clb.SetItemChecked(index, false);
}
}
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Consider that you might have nested controls, that a CheckedListBox may not be a direct child of a GroupBox . Consider a generic recursive loop like so:
void ClearSelected(ControlCollection controls)
{
if (controls == null || controls.Count == 0) return;
foreach (Control control in controls)
{
if (control is CheckedListBox) ((CheckedListBox)control).ClearSelected();
ClearSelected(control.Controls);
}
} This will encounter any CheckedListBox at any depth in the parent/child hierarchy of controls.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
ISA? How old is this machine?!
Anyway, you're going to have to write your own devices drivers, in C++, to communicate with the hardware. C# is NOT good at this part! You can use C# as a higher level controller, providing a user interface to the functions of the board.
Like leppie said, you'll need the Windows Driver Development Kit. Start here[^]!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|