|
I am designing a user control. There is one property that I would like to hide from the Property box at design time. Is there a way to do this? I would like to use the convenience of the property set method so it is easy to set during runtime, but prevent setting it to anything at design time.
Updated: Of course I found the answer just after posting, set an attribute above the property's code:
[Browsable(false)]
|
|
|
|
|
I have been experiencing some interesting side effects with user controls and transparency, this particular problem is creating havoc in an application I am developing in C#.NET. If there is anyone who knows of a way around the problem (other that not over lapping controls), I would be very grateful.
Steps to create the problem.
1) Insert two controls onto a form a button and a label.
2) Set the background of the form to have an image (any image, this is simply to make the issue more visible).
3) Set the background color of the label to Transparent.
4) Drag the label over the Button and when the transparent portion moves over the button, you will see the background image and not the button.
Maybe the Transparent color is miss-named and it should be called the XRay Color
Am I doing something wrong or is it too much to expect that a transparency should only show the control under the transparent section rather than look straight through all the controls down to the background.
This[^] picture shows the effect of this.
Cheers,
Simon
"Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
animation mechanics in SVG (my first abstract photo)
|
|
|
|
|
Hi Everyone,
Lets say I have a collection class (MyClassCollection ) that holds instances of another class I've defined (MyClass ). If I serialize the collection class (using a BinaryFormatter ) and then deserialize it later will I get back the exact same information? For example if I had the following line:
MyClassCollection[0] = new MyClass ("Hello"); If I then serialize and deserialize the MyClassCollection will this work as expected (assuming Name is a member of MyClass that gets it's value from the constructor):
string str = MyClassCollection[0].Name;
- monrobot13
|
|
|
|
|
Serialization and deserialization of MyClassCollection (and the instances of MyClass that it holds) will work properly so long as you apply SerializableAttribute to both MyClassCollection and MyClass . If either class is not marked with SerializableAttribute you will receive a SerializationException when you try to call BinaryFormatter.Serialize .
The following demonstrates the serialization of your classes:
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable()]
public class MyClass {
public MyClass(string name) {
_Name = name;
}
public string Name {
get { return _Name; }
}
private string _Name;
}
[Serializable()]
class MyClassCollection {
public MyClassCollection() {
_Items = new MyClass[4];
}
public MyClass this[int index] {
get { return _Items[index]; }
set { _Items[index] = value; }
}
public override string ToString() {
string result = "MyClassCollection {";
for (int i = 0; i < _Items.Length; i++)
result += (i != 0 ? ", " : "") + (_Items[i] != null ? _Items[i].Name : "[null]");
result += "}";
return result;
}
private MyClass[] _Items;
[STAThread]
static void Main(string[] args) {
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
MyClassCollection col = new MyClassCollection();
col[0] = new MyClass("Item #1");
col[2] = new MyClass("Item #2");
Console.WriteLine(col);
formatter.Serialize(stream, col);
col = null;
stream.Seek(0, SeekOrigin.Begin);
col = (MyClassCollection)formatter.Deserialize(stream);
stream.Close();
Console.WriteLine(col);
Console.Read();
}
}
Output:
MyClassCollection {Item #1, [null], Item #2, [null]}
MyClassCollection {Item #1, [null], Item #2, [null]}
Hope this helps.
|
|
|
|
|
Kastro wrote:
Hope this helps
That helps a lot. Thanks for the help.
- monrobot13
|
|
|
|
|
I get a StackOverFlowException when I try to assign values in an array to properties in a struct. Not sure what is going on, any one have any ideas? Here is the code:
//Main Class
public class BloombergEq
{
TradeData td = new TradeData();
public BloombergEq()
{
}
public ArrayList ExecuteTradeData()
{
string fileName = @"D:\CSharp\file2.txt";
ArrayList rows = new ArrayList();
try
{
FileStream bbFile = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(bbFile);
//Move the file cursor down 4 lines to get to start of data
sr.ReadLine();
sr.ReadLine();
sr.ReadLine();
sr.ReadLine();
while (sr.Read() != -1)
{
object[] tokens = new object[12];
int tokenIndex = 0;
string row = sr.ReadLine();
Regex r = new Regex("\\s(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))"); //matches all white space characters
//splits line at every white space
//disregards whitespaces & saves non-whitespace char
for (int i=0; i<=r.Split(row).Length-1;i++)
{
if(r.Split(row).GetValue(i).Equals(""))
{
continue;
}
else
{
tokens[tokenIndex] = r.Split(row).GetValue(i);
tokenIndex++;
}
} // for
Console.WriteLine(tokens[0]);
THIS IS WHERE THE ERROR IS THROWN
td.orderTime = tokens[0];
td.transactionType = (string)tokens[1];
td.ticker = (string)tokens[3];
td.price = (float)tokens[4];
td.fillQ = (float) tokens[6];
td.account = (string)tokens[7];
td.broker = (string)tokens[8];
td.status = (string) tokens[9];
rows.Add(td);
} //while
}
catch (Exception e)
{
Console.WriteLine(e);
}
return rows;
} //ExecuteTradeData
public static void Main(string[] args)
{
BloombergEq eq = new BloombergEq();
eq.ExecuteTradeData();
}
} //BloombergEq
//struct
public struct TradeData
{
public object orderTime
{
get
{
return orderTime;
}
set
{
orderTime = value;
}
}
public string transactionType
{
get
{
return transactionType;
}
set
{
transactionType = value;
}
}
public string ticker
{
get
{
return ticker;
}
set
{
ticker = value;
}
}
public float price
{
get
{
return price;
}
set
{
price = Convert.ToSingle(value);
}
}
public float fillQ
{
get
{
return fillQ;
}
set
{
fillQ = Convert.ToSingle(value);
}
}
public string account
{
get
{
return account;
}
set
{
account = value;
}
}
public string broker
{
get
{
return broker;
}
set
{
broker = value;
}
}
public string status
{
get
{
return status;
}
set
{
status = value;
}
}
} //struct
|
|
|
|
|
your problem is the way you wrote the properties.
//struct
public struct TradeData
{
public object orderTime
{
get
{
return orderTime;
}
set
{
orderTime = value;
}
}
this is a c# translation of the resulting IL created for that:
public Object get_orderTime() {
return get_orderTime();
}
public set_orderTime(Object value) {
set_orderTime(value);
}
both of these will obviously recurse until you stackoverflow.
either make those properties into fields, or provide internal storage for the public property.
|
|
|
|
|
|
Thanks for the response Andy. What do you mean by providing internal storage for public property? Thanks again.
|
|
|
|
|
something like this:
public struct TradeData {
public object OrderTime {
get {
return orderTime;
}
set {
orderTime = value;
}
}
private Object orderTime;
}
|
|
|
|
|
I'm creating a windows application.
Trough my main menu I want to toggle between diferent views using only one frame..
How can I do this using forms??
Please help!!
|
|
|
|
|
You could try using Panel s. Panel s are just container controls that host other controls. You would make a panel and populate it with the buttons, listboxes, etc for the first view. Then make a panel for the second view, populate that and so on. Then using your menus you can make each panel visible or invisible depending on the menu item clicked.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
We are working on creating two new newsgroups to discuss the ECMA/ISO standards for C# and the CLI. The first step in doing so is submitting a request for discussion, to see if there is interest in a group. If there is sufficient interest, a vote will be held later.
If you would like to have these groups, please respond to the posts in the news.groups newsgroups. You can also do this through google at:
C#
http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF-8&group=news.groups&selm=1057623961.29376%40isc.org
CLI
http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=1057624363.29389%40isc.org&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26group%3Dnews.groups
Thanks
Eric
EricGu@microsoft.com
|
|
|
|
|
|
Hello,
I have a problem that I'm still stuck on. I have a form with a pair of user controls. The first user control is displayed when the program runs. When a button is clicked, I want the first user control to remove itself from the form, and the second user control to appear.
However, when I write the code for the button, all I can do is get the first UC to disappear; the second UC never draws itself.
Someone earlier told me to instantiate an instance of the second user control in the form's constructor, and add this line into the form:
this.Parent.Controls.Add(newUserControl);
However, this still doesn't solve the issue of the first user control not knowing about the second user control. Can someone point me in the right direction?
|
|
|
|
|
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(64, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Location = new System.Drawing.Point(160, 112);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.Visible = false;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
private void button1_Click(object sender, System.EventArgs e)
{
button2.Visible = true;
button1.Visible = false;
}
private void button2_Click(object sender, System.EventArgs e)
{
button2.Visible = false;
button1.Visible = true;
}
}
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
How does this help answer the question? Where are the user controls?
|
|
|
|
|
If it helps, here my code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Copper
{
public class frmInit : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private Copper.UCInit ucInit1;
private System.ComponentModel.Container components = null;
public frmInit()
{
InitializeComponent();
UCCreate newPanel = new UCCreate();
newPanel.Location = new Point(376, 8);
newPanel.Size = new Size (280, 140);
this.Parent.Controls.Add(newPanel);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmInit));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.ucInit1 = new Copper.UCInit();
this.SuspendLayout();
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(375, 256);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// ucInit1
//
this.ucInit1.Location = new System.Drawing.Point(376, 8);
this.ucInit1.Name = "ucInit1";
this.ucInit1.Size = new System.Drawing.Size(280, 184);
this.ucInit1.TabIndex = 0;
this.ucInit1.Load += new System.EventHandler(this.ucInit1_Load);
//
// frmInit
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(664, 197);
this.Controls.Add(this.ucInit1);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "frmInit";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Mud Object Creator";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new frmInit());
}
Then I have the first control, entitled UCInit. Here's the relevant portion of it:
private void btnQuit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void btnCreate_Click(object sender, System.EventArgs e)
{
this.Hide();
//Code to draw UCCreate, the second user control,
//should go here. This is the part I need
//help with. Any thoughts?
}
|
|
|
|
|
OK here's a quick and dirty way Just make the button public.
Just add the following to the main form:
ucInit1.button.Clicked += new EventHandler(ShowUCCreate);
....
void ShowUCCreate(object sender, EventArgs e)
{
UCCreate newPanel = new UCCreate();
newPanel.Location = new Point(376, 8);
newPanel.Size = new Size (280, 140);
this.Parent.Controls.Add(newPanel);
}
You should get the idea. Once you understand events they make life alot easier.
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
I think that should work. Is there a good primer on Events and the EventHandler() method in general, somewhere?
|
|
|
|
|
frogb0x wrote:
Is there a good primer on Events and the EventHandler() method in general, somewhere?
The ones in MSDN are rather difficult to grasp. It took me quite a while to figure out what they are and why I need them.
To understand events you need to understand delegates. In fact an event is really just a very limited delegate.
A delegate (or function pointer) is basically a function/methods signature. WHat I mean by this is, is that it looks basically like a method but it has the delegate keyword. Think of this as a placeholder for a method.
Example:
delegate void FooHandler(string name);
class ABC
{
public FooHandler Foo;
public void InvokeFoo()
{
Foo("Hello from ABC");
}
}
class XYZ
{
static void MyFoo(string name)
{
Console.WriteLine(name);
}
static void Main()
{
ABC abc = new ABC();
abc.Foo = new FooHandler(MyFoo);
abc.InvokeFoo();
}
}
Now step into this with the debugger, step into every function (F11). This will show you exactly how it works. This allows you specify a method in a different place or you can change them dynamically.
Once you have grasped this, I suggest you look at the MSDN documentation on events.
Hope this helps
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
A C# windows application consist of two forms. Form1 and Form2. How can I offset Form2 just a little from Form1's starting location. (So it looks like two playing cards, one not quite covering the other.)
public Form2(Form1 myParentForm)
{ //form 2 is created referencing form 1
InitializeCommonConstructor();
m_myParentForm = myParentForm;
}
private void button1_Click(object sender, System.EventArgs e)
{ //move form2 over a little bit.
if(m_myParentForm != null)
{
int x = m_myParentForm.Location.X;
int y = m_myParentForm.Location.Y;
this.Location.Offset(x + 50, y + 50);
}
|
|
|
|
|
C#:
<font color="#0000FF">private</font> <font color="blue">void</font><font color="blue"></font> button2_Click(<font color="#0000FF">object</font> sender,<font color="blue"></font> System.EventArgs e) <br> { <br> Form2 frm=<font color="#0000FF">new</font> Form2(<font color="blue"></font><font color="blue"></font>); <br> <font color="#0000FF">int</font> x=<font color="#0000FF">this</font>.Location.X; <br> <font color="#0000FF">int</font> y=<font color="#0000FF">this</font>.Location.Y; <br> frm.Show(<font color="blue"></font><font color="blue"></font>); <br> frm.Location=<font color="#0000FF">new</font> Point(x-10,y-10); <font color="DarkGreen">
hope it helps
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
thank you that does help.
It is odd to me that the calling class sets the location and not the class itself. Seems very non OOP.
thanks again
|
|
|
|
|
I need to dynamically generate image and put some text on it.
The problem I'm having is that the text needs to be as if it was on a sphere.
Imagine 400x400 pixel ball and write some text on it. It will look different at top and bottom and right and left sides will be vanishing.
Can it be done thru matrix transoform? if so how would i set one up?
Thanks.
|
|
|
|