|
Have you checked any of the Win32 API calls? I know it's possible since Windows Media Player in full screen mode hides both the task tray and the mouse cursor after a few seconds of no keyboard/mouse activity.
[edit]Look at the ShowCursor[^] function or the SystemParametersInfo[^] function and setting SPI_SETMOUSEVANISH.[/edit]
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hello,
I have the following problem, In a window form I have a panel (with autosroll enabled) and inside this panel I would like to add dynamicly other panels. I have a variable that holds the number of panels inside the main Panel. So whenever I add a new panel,its location is calculated by (number_of_panels+space_between_two_panels)*panel_height
The code works fine.. until I scroll down the mainpanel to the bottom, then when I add a new panel inside it there is a huge gap between the last panel and the newly added one.
Any one can tell me why? and how to solve it ?(I dont want to scroll the main panel all the way up just to add a new panel).
Help appreciated,
Pawel
|
|
|
|
|
I think you have to somehow consider the value returned by the AutoScrollPosition property in your calculation.
"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 www.troschuetz.de
|
|
|
|
|
Hi,
what your are doing sound principally correct and the fact that you have scrolled shouldn't matter. I assume there is some little mistake in your implementation (probably you are using a wrong property at some place). You probably have to post some code.
Instead of calculating all positions yourself you could also with panel.Dock = DockStyle.Top to the container panel. This way the framework should handle the correct positioning.
Robert
|
|
|
|
|
Hi,
I write an application in C# 2003. this program should list all the available serial ports on the computer and display it for the user. I tried with MSComm and AXMSComm to identify the Serial ports. But this components have only a function by the name of “commport” that return the index of one port to be used. Is there any way to identify all the serial ports and theirs name?
Thanks for your help
/Babak
|
|
|
|
|
Hi,
I usually search the registry (HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM) for this information.
Regards,
Tim
|
|
|
|
|
Hi guys!
I need some help please, I have a treeview with many nodes and the nodes and sub nodes. i.e.
-Root
---Nodes
-----sub nodes
My nodes have a context menu which allows me to disable the subnodes and hence change the imageindex of the subnodes to an inactive icon. When I make this change I reload all the nodes and I would like to reload and go to the NODE on which I made the change. Basically refresh the treeview and jump to the make the selected node the node that I made the change on.
Please help!!!
sasa
|
|
|
|
|
With this c# code I try to write vb6 code. I am a newbie in C# and I think this is not a good approach to my need. I want to create a list of different objects that write the code, but list admit only the same kind of classes (type-safe, right?). I Know i can resolve this using List<object>, but your opinions are useful.
In the example below I do this.
root (form)
|
|--- eFrame
| |
| |--- eTxt (TextBox)
|
eLbl (label)
Example.
--------
public class Tester
{
static void Main()
{
FormControl root = new FormControl("Main", "frmMenu");
Element eFrm = new Element(root);
TextBoxControl txt = new TextBoxControl("txtName",false, " ");
Element eTxt = new Element(txt);
LabelControl lbl = new LabelControl("Name", " ");
Element eLbl = new Element(lbl);
FrameControl frame = new FrameControl("Frame", " ");
Element eFrame = new Element(frame);
frame.AddChild(eTxt);
root.AddChild(eLbl);
root.AddChild(eFrame);
Console.WriteLine(root.GenerateCode());
}
public class BaseControl
{
protected string name;
protected string indent = "";
protected List<element> elementsList;
public BaseControl(string name, string indent)
{
this.name = name;
this.indent = indent;
elementsList = new List<element>();
}
public string Indent
{
get { return indent; }
set { indent = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public void AddChild(Element e)
{
elementsList.Add(e);
}
}
public class FormControl : BaseControl
{
private string caption;
public FormControl(string caption, string name)
: base(name, "")
{
this.caption = caption;
}
public string GenerateCode()
{
string code = "";
code += indent + "Begin Form code\n";
foreach (Element e in elementsList) { code += e.GenerateCode(); }
code += indent + "End Form code\n";
return code;
}
}
public class FrameControl : BaseControl
{
private int index;
public FrameControl(string name, string indent)
: base(name, indent)
{
index = -1;
}
public FrameControl(string name, int index, string indent)
: base(name, indent)
{
this.index = index;
}
public int Index
{
get { return index; }
set { index = value; }
}
public string GenerateCode()
{
string code = "";
code += indent + "Begin Frame code\n";
foreach (Element e in elementsList) { code += e.GenerateCode(); }
code += indent + "End Frame code\n";
return code;
}
}
public class LabelControl : BaseControl
{
private string caption;
private static int index;
public LabelControl(string caption, string indent)
: base("", indent)
{
this.caption = caption;
index = 0;
}
public string GenerateCode()
{
string code = "";
code += indent + "Begin label code\n";
code += indent + " ....\n";
code += indent + "End lable code\n";
return code;
}
}
public class Element
{
private delegate string GenCodeDelegate();
private GenCodeDelegate doCode;
#region ' Contructor overloaded '
public Element(LabelControl lbl)
{
doCode = new GenCodeDelegate(lbl.GenerateCode);
}
public Element(TextBoxControl txt)
{
doCode = new GenCodeDelegate(txt.GenerateCode);
}
public Element(FormControl frm)
{
doCode = new GenCodeDelegate(frm.GenerateCode);
}
public Element(FrameControl frame)
{
doCode = new GenCodeDelegate(frame.GenerateCode);
}
#endregion
public string GenerateCode()
{
string code = "";
code = doCode();
return code;
}
}
Thanks in advance.
Gerard
Sorry for my english.
|
|
|
|
|
Hi,
I would define your class BaseControl as abstract (public abstract class BaseControl... ) and add a abstract method to it:
public abstract string GenerateCode();
Now every inheriting class needs to overwrite it:
public overridestring GenerateCode() {
}
Now its sufficient that your list only hold BaseControl instances and you won't need the class Element anymore.
Robert
|
|
|
|
|
Very useful, thank you!!.
|
|
|
|
|
As the subject says, how do I get a variable out of a user control?
I have a user control in my main form, which contains a text box. On pressing a button on the main form, I want a message box to pop up with whatever I put into the textbox.
So how do you do this? (I can do everything but get the text from the contrl to the messagebox in my main form)
Just a note, I need it this way, because later on the program is going to take a bunch of variables from multiple UserControls, and pass it into a global array.
- Munty
|
|
|
|
|
Hi,
define a property in your user control and access it from your main form:
public string MtyTextBoxText {
get { return myTextBox.Text; }
}
public void DoSomething() {
MessageBox.Show(myUserControl.MyTextBoxText);
}
Robert
|
|
|
|
|
That worked perfectly, thanks.
Now for another (probably silly) question.
The user control gets created by a button press. It gets added to an array.
Now I want a button in the UserControl that can remove that particular UserControl from the GUI (and stop the code from seeing it)
Now I can remove it from the GUI with the button inside the UserControl, but I'm not sure how (or if) you can remove the user control from the array in the main form, from the button in the user control.
So is this possible? (I'm assuming some sort of event handler could be used)
If not, I can work around the problem, but it would be better (much better) to remove the control from the array.
- Munty
|
|
|
|
|
Hi,
yes I would use an event in this case and also let the form remove the control instead of letting the control remove itself:
public event EventHandler RemoveButtonPressed;
if (RemoveButtonPressed != null)
RemoveButtonPressed(this, EventArgs.Empty);
myUserControl.RemoveButtonPressed += new EventHandler(OnRemoveButtonPressed);
private void OnRemoveButtonPressed(object sender, EventArgs ea) {
MyUserControl ctrl = (MyUserControl)sender;
ctrl.RemoveButtonPressed -= new EventHandler(OnRemoveButtonPressed);
}
Robert
|
|
|
|
|
Cool, thanks!
I'll try that out tommorow then.
- Munty
|
|
|
|
|
Hi All,
I am converting some of my vb.net code to c# and have run into a problem.
<br />
Select Case True<br />
Case p.ParameterType Is GetType(String)<br />
Response.Write("paramater is a string")<br />
End Select<br />
the code above works but when I try to convert to c# I get the error: A constant value is expected.
<br />
switch (true)<br />
{<br />
case pInfo.ParameterType == typeof(String): <br />
Response.Write("is type of string");<br />
break;<br />
<br />
}<br />
Is there any way to do this in c#?
thanks
tom
|
|
|
|
|
I'm not sure this has to do anything with a switch statement, but try this one:
if(p.ParameterType is string) Response.Write("is type of string");
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The variable goes in the switch part, the constants go in the case part.
switch(pInfo.ParameterType)
{
case typeof(string):
break;
}
Although I'm not sure how it handles Type s. I've only ever used a switch statement for numbers, strings and enumerators.
|
|
|
|
|
Thanks for the reply. I tried that but then I get the error:
A value of an integral type expected
this is the only work around that I can think of, but it isnt really an ideal solution:
switch (pInfo.ParameterType.Name)
{
case "String":
Response.Write("is type of string");
break;
}
I cant believe you cant do this in c#!
thanks
|
|
|
|
|
mcd2424 wrote: I cant believe you cant do this in c#!
I would imagine that C# is enforcing some additional restrictions in order to produce optimised code - something VB is trading for ease of coding.
|
|
|
|
|
Hi,
the switch statement isn't designed for such a thing. Use if-then-else-if instead:
if (pInfo.ParameterType == typeof(String)) {
Response.Write("is type of string");
} else if (...) {
} else if (...) {
}
Robert
|
|
|
|
|
Robert Rohde wrote: the switch statement isn't designed for such a thing.
Please explain
only two letters away from being an asset
|
|
|
|
|
Hi,
this simply means it can only work with values which are internally represented by integers. This applies to integer types, boolean and enumeration values. Don't ask me why MS didn't extend its capabilities - its just a fact.
Robert
|
|
|
|
|
Robert Rohde wrote: can only work with values which are internally represented by integers
Then I must be doing something wrong for this to work
string MyString = "Foo";<br />
switch(MyString)<br />
{<br />
case "Foo":<br />
break;<br />
case "Bar":<br />
break;<br />
default:<br />
break;<br />
}
only two letters away from being an asset
|
|
|
|
|
Hi,
as usual string seems to get a special treatment . Probably there are some more case where switch works, but the fact remains that its rather limited (compared to some other languages).
Robert
|
|
|
|