|
Boipelo wrote: I was also scared of "...if they add another element with a numeric value"
but only if it is first.
You can do a indexOf for the element name and then start parsing the numeric.
|
|
|
|
|
I'm trying to add an event handler for form closing event. I'm not very good at doing event handlers. I looked at http://stackoverflow.com/questions/7076751/how-do-i-avoid-validating-cancel-causing-app-exit-to-hang[^], among other places on the internet, but the thread is not getting to my method. It wasn't building until I added the property for FormClosing at the top. Hopefully someone here has an idea why it's not working. Thanks!
public partial class GenericPC : UserControl
{
...
public FormClosingEventHandler Closing { get; set; }
public Control GetPC(<params>)
{
...
this.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
}
private void updateLogsOnClose(object sender, System.ComponentModel.CancelEventArgs e)
{
logCountsToFile(logCountFile);
}
...
}
modified 21-Mar-13 11:28am.
|
|
|
|
|
The event name is Closing .
|
|
|
|
|
I changed it from FormClosing to Closing, as I changed in my code shown above, and it's still not going to my method when the form closes. Any ideas? It doesn't seem the like property for Closing gets called by anything. Do I need to set it somehow? Closing was causing a build error before I defined it. Maybe there's a system method I need to enable somewhere to get it defined by visual studio?
|
|
|
|
|
MichCl wrote: property for Closing
Get rid of that.
|
|
|
|
|
public Control GetPC(<params>)
{
...
this.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
} That's not the form, and your usercontrol will not raise a FromClosingEvent; you'd need a reference to the form if you want to hook it's "Closing" handler (in the same way you need an instance when you use one of it's properties).
Alternatively, you could use the "Parent" property of your usercontrol to find the owning form.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy. I'm trying to figure out how to use theParent's Form to set me up with the Closing Handler. For some reason, the below code is not building. It says "System.Windows.Forms.FormClosingEventHandler is a type which is not valid in the given context". Any idea?
public partial class GenericPC : UserControl
{
...
public FormClosingEventHandler Closing { get; set; }
public Control GetPC(<params>, Form theParent)
{
...
theParent.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
}
private void updateLogsOnClose(object sender, System.ComponentModel.CancelEventArgs e)
{
logCountsToFile(logCountFile);
}
...
}
|
|
|
|
|
Your modification is correct; but it looks like the eventhandler could use a different signature;
private void updateLogsOnClose(Object sender, FormClosingEventArgs e) As an alternative solution;
1 using System;
2 using System.Windows.Forms;
3 using System.Collections.Generic;
4
5 namespace test
6 {
7 class MyControl: UserControl
8 {
9 protected override void OnHandleCreated(EventArgs e)
10 {
11 base.OnHandleCreated(e);
12 FindForm().FormClosing += new FormClosingEventHandler(MyControl_FormClosing);
13 }
14 void MyControl_FormClosing(object sender, FormClosingEventArgs e)
15 {
16 System.Diagnostics.Debugger.Break();
17 }
18 }
19 class Program
20 {
21 public static void Main(string[] args)
22 {
23 using (var f = new Form())
24 {
25 MyControl uc = new MyControl() { Dock = DockStyle.Fill };
26 f.Controls.Add(uc);
27 f.ShowDialog();
28 }
29 }
30 }
31 }
The reason I'm not calling the FindForm method in the constructor of the UserControl is because it will not be assigned to a form at that point. (It's created on line 25, and added to the form on the next line)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If you definitely need access to the closing event from your control, you need to walk up the Parent hierarchy until you find the Form. It would look something like this:
private Form ParentForm(object item)
{
if (((Form)item).Parent is Form)
return ((Form)item).Parent;
return ParentForm(item);
} Then, it's a simple matter of hooking into the closing event handler.
I really wouldn't recommend doing it this way, but you could.
|
|
|
|
|
I got it working!! Thanks for your help!! It turns out I was missing "new":
theParent.FormClosing += new FormClosingEventHandler(this.updateLogsOnClose);
|
|
|
|
|
Hi,
I want to combine two drawings into one,and place in a line as show below
How to Upload pictures!!!
|
|
|
|
|
You need to provide a lot more detail about this problem: what sort of drawings, place on a line where ... ?
Use the best guess
|
|
|
|
|
Could you teach me how to upload pictures? I have no idea
|
|
|
|
|
What sort of pictures, and where do you want to upload them from and to? You really need to think about what problem you are trying to solve, and provide some more useful details.
Use the best guess
|
|
|
|
|
You are not allowed to upload pictures here. You should upload them to a free image hosting site and provide a link in your question. You also need to be a bit clearer in your question, as I don't think anyone understands what you are trying to get at. If your English is not so good, try use Google translate.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
What format are the drawings in and how do you want to combine them?
|
|
|
|
|
The drawings are designed by AutoCAD(*dwg/*dxf). For each drawing document, there is only one drawing of A4 size. Now, I want to gather 2 drawing-files into a drawing file, so that ,I can preview the 2 drawings in a file at the same time.
|
|
|
|
|
Seems simple enough, and I have looked hard and found many code sources (because some here might say this has been asked and answered), but none of them seem to work (I am showing some below...there are more).
Teh primary error seems to be the following error (unable to cast object of type 'system.data.datarowview' to type 'system.string ) or something similar to this. It seems like I solved this problem a while ago by giving up on the check list box and using a list view box with the show checkbox property added, but I cannot find my original code. So, in a nutshell....I want to simply return the string values for the checked items in the control and add them to an array or arraylist (either will do). BTW...the checklistbox control was filled using an SQL query (shown also), in case that makes a difference. You guys have almost always come up with a solution of sorts, and I thank you again in advance for your great assistance and talent...Regards, Pat
//Query Code
ArrayList al = new ArrayList();
Conn.Open();
SqlDataReader dr = Comm.ExecuteReader();
if (dr != null)
while (dr.Read())
{
al.Add(dr[0]);
}
Conn.Close();
foreach(string s in al)
{
checkedListBoxServices.Items.Add(s);
}
|
|
|
|
|
using System;
using System.Windows.Forms;
using System.Collections.Generic;
namespace test
{
class Program
{
public static void Main(string[] args)
{
using (var f = new Form())
{
var tb = new TextBox()
{
Multiline = true,
Dock = DockStyle.Top,
Height = 50
};
var clb = new CheckedListBox() { Dock = DockStyle.Fill };
clb.Items.AddRange(new string[] { "One", "Two", "A half" });
clb.SetItemChecked(0, true);
clb.SetItemChecked(2, true);
f.Controls.AddRange(new Control[] { clb, tb });
foreach (var element in clb.CheckedItems)
{
tb.Text += ((string)element) + Environment.NewLine;
}
f.ShowDialog();
}
}
}
} "CheckedItems" will return the objects that are checked. If you throw strings in there, then it's strings that it returns. Otherwise, it'll return the object, and you'd prolly need to call the "ToString" method on that object or build a string of it's properties.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
YES YES YES YES YES YES YES YES ...........
Thank You Eddy...VERY Much...I'd be too embarrassed to tell you how much time I spent of this yesterday. The following is the actual code that I extracted from your sample to resolve this:
foreach (var element in checkedListBoxServices.CheckedItems)
{
textBox1.Text += ((string)element) + Environment.NewLine;
}
It seems that your use of the new context (var) replacing my use of string and then casting for the result later with (string) makes a big difference ... I need to look at this again to really understand it, but I know that I can thanks to you. Much appreciation and thanks...Best Regards, Pat
ps: after searching for this yesterday, and finding 'solutions' that were a page long and STILL did not work, I am sure that hundreds of others will be wanting the thank you as well for a concise usable solution... Pat
|
|
|
|
|
You're welcome 
|
|
|
|
|
Hi at all & tks in advance.
I wrote a class for manage backdata (data,error and so on) from a wcf which expose several and different function.
The scope is to make a same frame for back data.
This class are like this:
[DataContract(Name = "WS Back Data Frame",IsReference = true)]
[System.Serializable()]
public class WSBackDataFrame <C> where C : class
{
[DataMember]
public List<C> DataCollection;
[DataMember]
public bool IsOk
{
get { return this.FaultType == AppFaultType.NoFailure; }
private set { }
}
...
....
}
Now i declare exposed methods like this:
public WSBackDataFrame <Class_1> (....);
public WSBackDataFrame <Class_2> (....);
...
...
but i recived error for duplicated reference for WSBackDataFrame...
I've done a porting from WebServices to WCF ... in WebServices when i published the system created 2 different classes like
WSBackDataFrameofClass_1
WSBackDataFrameofClass_1
What is wrong in declaration?? What WCF expects?
tks and sorry for my bad english
|
|
|
|
|
anymalo wrote: but i recived error for duplicated reference for WSBackDataFrame...
During compilation? Sounds like you added the same class more than once, and that would confuse the compiler. Try renaming your class; if it works after that, you've got a copy of the class "somewhere" in your code.
anymalo wrote: WSBackDataFrameofClass_1
WSBackDataFrameofClass_1
When you mention "WSBackDataFrameofClass_1" in code, how would the compiler know which of those two classes you meant? Put them in a separate namespace to make them unique, or change on of the names.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: During compilation? Sounds like you added the same class more than once, and that would confuse the compiler. Try renaming your class; if it works after that, you've got a copy of the class "somewhere" in your code.
No, i have not specified.
The error appear on execution of wcf
Eddy Vluggen wrote: When you mention "WSBackDataFrameofClass_1" in code, how would the compiler know which of those two classes you meant? Put them in a separate namespace to make them unique, or change on of the names.
The reference file created by WBServices export this definition of those classes but in a prevoius prj that are not wcf(and it work!!!!).
I specified this only because i though wcf will be same behaviour...
modified 20-Mar-13 9:17am.
|
|
|
|
|
anymalo wrote: The reference file created by WBServices export this definition of those classes but in a prevoius prj that are not wcf(and it work!!!!).
Same problem; two classes with the samen namespace/classname in a single project will fail.
Also, the client would need a reference to the assembly containing the WBServices.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|