|
use @"\* " or "\\* "
SkyWalker
|
|
|
|
|
I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?
|
|
|
|
|
How do you mean - save to where ? To a file ? To each other ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
|
Expose the TextBox.Text property as a property of your UserControl . eg
public string TextBoxText
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
|
|
|
|
|
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming.
I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g
"txtName.Text = clsProject.Name"
My Question is :
I would like to display it in all my tabpages. But how could I? I would like to do this in following manner.
tabcontrol1.tabpages1.textName.text = clsProject.Name
tabcontrol1.tabpages2.textName.text = clsProject.Name
So that I can save the corresponding tab pages text box control values
in a routine name Save(), if the user changes the Name of for each tabpages.
e.g.
Void Save()
{
clsProject.Name = tabcontrol1.tabpages1.textName.text
clsProject.Name = tabcontrol1.tabpages2.textName.text
}
Can you tell me how can I resolve this problem ?
|
|
|
|
|
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming.
I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g
"txtName.Text = clsProject.Name"
My Question is :
I would like to display it in all my tabpages. But how could I? I would like to do this in following manner.
tabcontrol1.tabpages1.textName.text = clsProject.Name
tabcontrol1.tabpages2.textName.text = clsProject.Name
So that I can save the corresponding tab pages text box control values
in a routine name Save(), if the user changes the Name of for each tabpages.
e.g.
Void Save()
{
clsProject.Name = tabcontrol1.tabpages1.textName.text
clsProject.Name = tabcontrol1.tabpages2.textName.text
}
Can you tell me how can I resolve this problem ?
|
|
|
|
|
If you want them to all be the same, then make a static property that stores the string, and a static array of textboxes, which each textbox adds itself to. Then, changing it in one instance, will change it in all.
The other option is to set up a delegate, so each control lets the parent form know when it's changed, and it sets them all, with the sort of code you have above.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You mean in each tab the value of the textbox to be always the same?
|
|
|
|
|
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming.
I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g
"txtName.Text = clsProject.Name"
My Question is :
I would like to display it in all my tabpages. But how could I? I would like to do this in following manner.
tabcontrol1.tabpages1.textName.text = clsProject.Name
tabcontrol1.tabpages2.textName.text = clsProject.Name
So that I can save the corresponding tab pages text box control values
in a routine name Save(), if the user changes the Name of for each tabpages.
e.g.
Void Save()
{
clsProject.Name = tabcontrol1.tabpages1.textName.text
clsProject.Name = tabcontrol1.tabpages2.textName.text
}
Can you tell me how can I resolve this problem ?
|
|
|
|
|
I really can't understand what you are after!
Also in your code snipets you have two sequencial commands that practically ony the second has meaning.
By the way posting the same in two different persons trying to help and asking different questions is not the way.
|
|
|
|
|
I have 4 different cases for you:
If you need the same TextBox in each of your tab pages, you may consider adding one TextBox
to the TabControl (i.e. outside the tab pages) rather than to each individual page.
If you need the same TextBox on some of your tab pages, you may still put it on the tab control
(outside the tab pages) and you could alter its Visible state according to which tab page
is currently active.
If you need the same TextBox on some of your tab pages, and the instances have identical
properties (such as font, backcolor, location, size, etc), then I would use Visual Studio
Designer to add such TextBox to one of the pages, then programmatically add the same instance
of TextBox to the other relevant tab pages. Something like
tabpage.Controls.Add(myExistingTextBoxFromTabPage1);
Then there is no doubt whatever relevant tab page you select you would see the same TextBox
content, since there is actually only one instance.
This will save you a lot of code that would otherwise be needed to keep multiple TextBoxes
in sync.
If your TextBoxes have different attributes on different tab pages, more code will be
unavoidable.
Luc Pattyn
|
|
|
|
|
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming.
I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g
"txtName.Text = clsProject.Name"
My Question is :
I would like to display it in all my tabpages. But how could I? I would like to do this in following manner.
tabcontrol1.tabpages1.textName.text = clsProject.Name
tabcontrol1.tabpages2.textName.text = clsProject.Name
So that I can save the corresponding tab pages text box control values
in a routine name Save(), if the user changes the Name of for each tabpages.
e.g.
Void Save()
{
clsProject.Name = tabcontrol1.tabpages1.textName.text
clsProject.Name = tabcontrol1.tabpages2.textName.text
}
Can you tell me how can I resolve this problem ?
|
|
|
|
|
Since you want the TextBox visible on each of the tab pages, I would go for one of these
two possibilities:
1)
-with Designer (or programmatically) add the TextBox on the first tab page (say it is named
"textName1"), and leave the same place free on all other tab pages
- programmatically add the SAME TextBox to the other tab pages. Something like:
bool firstPage=true;
foreach (TabPage page in myTabControl) {
if (!firstPage) page.Controls.Add(textName1);
firstPage=false;
}
Of course you could also use the tab page names explicitly:
tabPage2.Control.Add(textName1);
tabPage3.Control.Add(textName1);
tabPage4.Control.Add(textName1);
or
2)
do not add the TextBox to one or more tab pages, but add it to the form that is holding
the tab control (not "to the tab control" as I had put in my previous post, that was
slightly wrong, really to the form holding the tab control).
In both cases, there is only one TextBox control, it is named textName1, so you have
to set its text only once, have to save its text only once, etc.
Luc Pattyn
|
|
|
|
|
for example:
//---------------------------------------------
// Sender
//---------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WinFormSendMsg
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
const int WM_COPYDATA = 0x004A;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(205, 231);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6F, 13F);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox1
this.textBox2});
this.Name = "Form1";
this.Text = "Sender";
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new Form1());
}
[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
ref COPYDATASTRUCT lParam // second message parameter
);
[DllImport("User32.dll",EntryPoint="FindWindow")]
private static extern int FindWindow(string lpClassName,string
lpWindowName);
private void button1_Click(object sender, System.EventArgs e)
{
int WINDOW_HANDLER = FindWindow(null,@"Accepter");
if(WINDOW_HANDLER == 0)
{
}
else
{
COPYDATASTRUCT cds;
cds.dwData = (IntPtr) 100;
WholeInfo wi = new WholeInfo();
wi.m_centralFilePath = this.textBox1.Text;
wi.m_localFilePath = this.textBox2.Text;
cds.cbData = Marshal.SizeOf(wi);
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(wi));
Marshal.StructureToPtr(wi, p, true);
cds.lpData = p;
SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds);
}
}
}
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
public struct WholeInfo
{
public String m_centralFilePath;
public String m_localFilePath;
};
}
//------------------------------------------------------------
//Accepter:
//------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsFormGetMsg
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null;
const int WM_COPYDATA = 0x004A;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(432, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1
this.textBox2});
this.Name = "Form1";
this.Text = "Accepter";
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new Form1());
}
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_COPYDATA:
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
WholeInfo h;
h = (WholeInfo)Marshal.PtrToStructure(mystr.lpData, typeof(WholeInfo));
this.textBox1.Text = h.m_centralFilePath;
this.textBox2.Text = h.m_localFilePath;
break;
default:
base.DefWndProc(ref m);
break;
}
}
}
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
public struct WholeInfo
{
public String m_centralFilePath;
public String m_localFilePath;
};
}
-------------------------------------------------------------------------
above is my test code, but there are some problem,sometimes it will crash, sometimes the Accepter Form's textBox1 and textBox2.Text display null or other error letter,never correct!
If any boy know the method to solve those problem,please teach me, it is better to give out the right code,full of thanks!
JimmyHu
|
|
|
|
|
As far as I understand your code, you managed to create a copy of the WholeInfo struct
in some memory that is accessible to the other process.
Unfortunately, that struct contains only 2 pointers (a string is a reference type),
and these pointers are NOT valid in the other process (which has a different address space).
So you are nowhere yet.
Are you sure you need WM_COPYDATA ?
There are other ways to transfer data.
Some suggestions:
1) the easiest is to make your struct completely value typed (things like int, but not
class objects, nor arrays). This should work with the code you have, but will not solve
your problem for passing strings.
2) use named pipes; it takes some setting up, but there is no address space problem involved,
once the pipe has been established you do WriteFile at one end, and ReadFile at the other;
this does not provide a signal to the other process, so it better has an extra thread
that just opens the pipe and reads (and waits until something is read).
BTW you will need PInvoke for this.
3) use memory mapped files; very similar to named pipes.
4) there must be an easy way based on .NET Remoting; this involves a new serializable class
that contains your data, and a TCP channel to transfer it to the other process. I did this
once but got fed up with Firewall hassles, so I switched to using named pipes for passing
the command line from one app to another (when I want the app to behave as a singleton).
For .NET Remoting there are articles on CodeProject.
Luc Pattyn
|
|
|
|
|
Thank you very much!
I will try your suggestions, thanks again!
JimmyHu
|
|
|
|
|
This article[^] just appeared on CodeProject; it shows how to marshal multiple strings using C++.
I havent read it yet, but from its length you might conclude it is not all that easy; I dont
think it being C++ code (rather than C#) adds to the complexity...
So I maintain my earlier suggestions.
Luc Pattyn
|
|
|
|
|
Hi,
I'm a noob and desparately need help with this.
I have an XML file and I'm suppose to select the element attrib(<link href="XXX_SUMMARY.xml" /> from node with title="Summary". Attached below is sample of the XML. Can anyone pls help me. I'm at a loss.
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>XXX</title>
<link rel="alternate" href="http:xxx.xml" />
<link rel="next" href="http://xxx.xml" />
<dc:creator>XXX</dc:creator>
<entry>
<title>Jam</title>
<link href="XXX_JAM.xml" />
<category term="Route" scheme="521" />
<category term="TimeStamp" scheme="20070201101329430" />
<author>
<name>XXX</name>
</author>
<id>XXX_JAM.xml</id>
<published>2007-02-01T02:13:29Z</published>
<summary type="text">Jam Cleared</summary>
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:13:29Z</dc:date>
</entry>
<entry>
<title>Summary</title>
<link href="XXX_SUMMARY.xml" />
<category term="Route" scheme="137" />
<category term="TimeStamp" scheme="20070201101319852" />
<author>
<name>XXX</name>
</author>
<id>XXX_SUMMARY.xml</id>
<published>2007-02-01T02:13:19Z</published>
<summary type="text">EVENT_SUMMARY</summary>
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:13:19Z</dc:date>
</entry>
<entry>
<title>Report</title>
<link href="XXX_REPORT.xml" />
<category term="Route" scheme="9" />
<category term="TimeStamp" scheme="20070201100628191" />
<author>
<name>XXX</name>
</author>
<id>XXX_REPORT.xml</id>
<published>2007-02-01T02:06:28Z</published>
<summary type="text" />
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:06:28Z</dc:date>
</entry>
</feed>
|
|
|
|
|
Google for XPath, that' s the language you use to search XML.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I've tried Xpath but I can't seem to get the correct node...help anyone pls...thanks...
XPathDocument doc = new XPathDocument("sample.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/feed/entry[title='Summary']");
XPathNodeIterator iterator = nav.Select(expr);
listBox1.Items.Add(iterator.Current.Value);
|
|
|
|
|
Hi,
I don't know exactly what the problem is but it seems to lie somewhere in your xmlns...
I loaded your xml into a XmlDocument and tried to SelectSingleNode("feed") but it wouldn't work. As soon as I removed all the xmlns except the one directly referenced in the doc (xmlns:dc) it worked!
.....further investigation.... more to the point take this out xmlns="http://www.w3.org/2005/Atom" and it should work. I don't know why, must be a conflict of sorts.
|
|
|
|
|
thanks but i still can't get my desired output. actually i want to search for all nodes with <title>=summary and grab the next node attribute<link href> to get the links. The earlier code was a trial to see if i can select a correct node.
can anyone pls kindly help me get the correct link node pls...thanks
-- modified at 20:34 Thursday 1st February, 2007
|
|
|
|
|
The problem is that your top-level element declares a default namespace (xmlns="http://www.w3.org/2005/Atom") that is valid for all nested elements. This means that your feed and entry have a qualified name of "{http://www.w3.org/2005/Atom}feed" or "{http://www.w3.org/2005/Atom}entry" respectively. Your XPath on the other hand is looking for unqualified feed and entry elements i.e. those declared in the empty namespace. Because your document does not contain such elements nothing is found. To resolve this use the overload of the Select method that takes an IXmlNamespaceResolver . Take a look at the example given by the respective MSDN topic and you should be able to work this out.
"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
|
|
|
|
|
sorry but I'm unclear on how to use the IXmlNamespaceResolver. Tried googling for example on the usage but still unclear. Anyone pls kindly point me in the right direction. Thanks.
|
|
|
|