|
Er... I did reply in C#!!!
The code Behind is in C#, the XAML is, well XAML, but that's the way of WPF, even in a C# project!
From your remark I could be under the impression that you are doing WinForm development.
However "It consists of a button with two labels on it" is not really possible in WinForm.
So I'm at loss as to what you are doing...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
As I said earlier, it's quite unclear what you are doing but...
I'm guessing it can be...
You are doing WinForm development
You added a Button and a Label to a UserControl and positioned the Label on top of the button.
Am I right?
Frankly I'm surprised you can click on the button at all!
But you should not do that!
Why not, instead, set the .Text and .ForeColor properties of the button?!!?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
OK lets see if I can clarify:
I have a user control consisting of a button with two labels on it, one for displaying a song title , the other for displaying the artist.
Im using the control in a flowlayout panel with multiple instances of the control. When a user clicks on the control, another form with information about the song is displayed.
Problem is, using the onClick event, If I click on top of one of the labels I have to click it twice to trigger the click event for the control. I need to be able to only have to click it once.
|
|
|
|
|
I'm sorry but I still don't get it, could you write some code?
If I would guess, I would say it looks like your control is like that:
public class MyControl : Control<br />
{<br />
public MyControl()<br />
{<br />
var b = new Button();<br />
b.Size = new Size(80, 40);<br />
b.Controls.Add(new Label { Text = "L1", Bounds = new Rectangle(10, 10, 20, 20), BackColor = Color.Transparent });<br />
b.Controls.Add(new Label { Text = "L2", Bounds = new Rectangle(50, 10, 20, 20), BackColor = Color.Transparent });<br />
<br />
Controls.Add(b);<br />
b.Click += new EventHandler(b_Click);<br />
}<br />
<br />
void b_Click(object sender, EventArgs e)<br />
{<br />
Console.WriteLine("Clicked");<br />
}<br />
}<br />
Well, and I'm still surprised you can click on the label at all!
Nothing happen when I click on the label, be it 1 or 100 times!
And it's not the way to handle button.
I decided to stop investigating this pointless undefined problem and thought I could show you what I would do instead.
I would define a control, which looks like a button, and display what I need!
Here you go:
class MyControl2 : Control<br />
{<br />
public MyControl2()<br />
{<br />
PushButtonState = PushButtonState.Normal;<br />
Size = new Size(100, 50);<br />
}<br />
<br />
protected override void OnClick(EventArgs e)<br />
{<br />
base.OnClick(e);<br />
Console.WriteLine("Clicked");<br />
}<br />
<br />
public PushButtonState PushButtonState { get; private set; }<br />
<br />
protected override void OnMouseDown(MouseEventArgs e)<br />
{<br />
base.OnMouseDown(e);<br />
PushButtonState = PushButtonState.Pressed;<br />
Invalidate();<br />
}<br />
protected override void OnMouseUp(MouseEventArgs e)<br />
{<br />
base.OnMouseUp(e);<br />
PushButtonState = PushButtonState.Normal;<br />
Invalidate();<br />
}<br />
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
ButtonRenderer.DrawButton(e.Graphics, new Rectangle(0, 0, Width, Height), PushButtonState);<br />
<br />
e.Graphics.DrawString("Label1", Font, Brushes.Red, new PointF(10, 10));<br />
e.Graphics.DrawString("Label2", Font, Brushes.Blue, new PointF(50, 10));<br />
}<br />
}<br />
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Here is my code. Im using visual studio. I added the button and two labels in the designer.
public partial class btnPlacard : UserControl
{
int height, width;
public btnPlacard()
{
InitializeComponent();
}
public string text1
{
get { return lbl1.Text; }
set { lbl1.Text = value; }
}
public string text2
{
get { return lbl2.Text; }
set { lbl2.Text = value; }
}
public string tag1
{
get { return lbl1.Tag.ToString(); }
set { lbl1.Tag = value; }
}
public string tag2
{
get { return lbl2.Tag.ToString(); }
set { lbl2.Tag = value; }
}
public int labelHeight
{
set
{
height = value;
lbl1.Size = new Size(btn.Size.Width, (int)(value * .45));
lbl2.Size = new Size(btn.Size.Width, (int)(value * .40));
}
}
public int labelWidth
{
set
{
width = value;
lbl1.Size = new Size(value, (int)(height * .45));
lbl2.Size = new Size(value, (int)(height * .40));
}
}
public int font1
{
set { lbl1.Font = new Font("Microsoft Sans Serif", value, FontStyle.Bold); }
}
public int font2
{
set { lbl2.Font = new Font("Microsoft Sans Serif", value, FontStyle.Bold); }
}
private void lbl1_Click(object sender, EventArgs e)
{
lbl1.Click += new System.EventHandler(PassThrough_Click);
}
private void lbl2_Click(object sender, EventArgs e)
{
lbl2.Click += new System.EventHandler(PassThrough_Click);
}
private void PassThrough_Click(object sender, EventArgs e)
{
base.OnClick(e);
}
public void relocate()
{
lbl1.Location = new Point(0, (int)(height * .15));
lbl2.Location = new Point(0, (int)(height * .52));
}
}
|
|
|
|
|
Hi all... I'm looking for a control similar to Properties Window[^] in the visual studio (C#, VB...)
The use: I'm looking for a control that: has two columns, one to show a properties, the other for a corresponding value (each property can have only one value), also I want to unite some properties under a groups. the "Properties Window" is the perfect control I can think of.
Question is: is there such a control anyway??, if not what control can you suggest that support the requirements above?
|
|
|
|
|
Yes. Look at the PropertyGrid control in MSDN. There's also quite a few attributes which can be applied to properties which change how they look in the PropertyGrid; you may want to have a look at those as well
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thanks, that was exactly what I was looking for!
|
|
|
|
|
the PropertyGrid is a great control, problem is that it has only one way to work with it: the PropertyGrid can only get an instance of an object and displays properties based on the set/get functions of that object (based on what I have learned). is there another way to populate the PropertyGrid?, say by row? (to set the values of rows/columns)
modified on Monday, August 3, 2009 5:07 AM
|
|
|
|
|
|
Ok, I know it has something to do with Spy++ Or Windows Hooks or maybe both, whatever the method is, how would you track the coordinates of an open window "say, My Documents folder floating window on my desktop".
|
|
|
|
|
Not sure, but I guess GetWindowRect method will help you out.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus
|
|
|
|
|
|
Hi, Ive just started using vs2008
im trying to call a method in a parent aspx page from a user control.
ive usually done this using something like:
((PageClass)this.Page).Method();
But for some reason PageClass never appears in intellisense...
- I cant reference the page class from the control.
Ive put the page and the control in the same namespace but still no luck.
Ive also tried using events instead - but after the event is assigned in the parent it still seems to be null in the control...
Any ideas what im doing wrong??
Thanks,
Chas
|
|
|
|
|
This is C# Forum. Your question is related to ASP.NET. So please Post it to ASP.NET Forum.
Thanks
|
|
|
|
|
You can access the method this way:
((ClassNameOfASPXPage)(this.Page)).MethodName();
Make sure the method is internal/public .
It's not necessary to be so stupid, either, but people manage it. - Christian Graus
|
|
|
|
|
Hi,
Thats what ive been trying - but 'ClassNameOfASPXPage' just isnt available in the control.
- Ive put them in the same namespace, no luck - ive put them in different namespaces and added a reference in the control to the parent namespace - but the parent namespace is not available...
The funny thing is - if i create 2 aspx pages lets say 1 is public testclass1 and the other is public testclass2 - I cant reference testclass1 from testclass2 - even if they are in the same namespace. surely something is wrong here but i cant figure out what...
Thanks,
Chas
|
|
|
|
|
OK,
adding a directive like <%@ Reference Page= "~/TestPage1.aspx" %> to the control
will make the parent class available...
but a better way of doing this was to use events...
in the control:
public delegate void GridEventHandler(CategoryType categoryType);
public event GridEventHandler GridItemSelected;
private void OnGridItemSelected(CategoryType categoryType)
{
if (GridItemSelected != null)
{
GridItemSelected(categoryType);
}
}
called using:
OnGridItemSelected(selectedCT);
and in the parent page:
categoryTypeGrid.GridItemSelected += new Controls_CategoryTypeGrid.GridEventHandler(categoryTypeGrid_GridItemSelected);
modified on Sunday, August 2, 2009 9:17 AM
|
|
|
|
|
I need to check whether a username and password are valid, and if so, if that user is in a special group on Active Directory.
I'm developing an intranet only system that (hopefully) will allow a user to login at program startup using their Active Directory credentials.
If anyone knows any C# code that does this it would be greatly appreciated. I've done a thorough Google search, but haven't found anything that returns a helpful response.
Thanks
|
|
|
|
|
|
I've already tried the options on that site, one enabled me to check whether a user was able to logon to the active directory, but not what groups it is in, and I've been unable to get Get "Get User Group Memberships" working; it gives an unspecified error on:
public ArrayList AttributeValuesMultiString(string attributeName,
string objectDn, ArrayList valuesCollection, bool recursive)
{
DirectoryEntry ent = new DirectoryEntry(objectDn);
PropertyValueCollection ValueCollection = ent.Properties[attributeName];
System.Collections.IEnumerator en = ValueCollection.GetEnumerator();
while (en.MoveNext())
{
if (en.Current != null)
{
if (!valuesCollection.Contains(en.Current.ToString()))
{
valuesCollection.Add(en.Current.ToString());
if (recursive)
{
AttributeValuesMultiString(attributeName, "LDAP://" +
en.Current.ToString(), valuesCollection, true);
}
}
}
}
ent.Close();
ent.Dispose();
return valuesCollection;
}
|
|
|
|
|
Hey peoples ............ if I am not late i was just to tell you that there is a nice iGrid.Net dll which is used as listViewItem ................. I got it yesterday from this site .................... on latest news on C# ................... have a look @ it and give your suggestions
Thanks a lot
|
|
|
|
|
Dear all
am new to c#(2008).
i created a stored procedure in sql server 2000.
"select * from employee where joindate between @d1 and @d1"
I was using Table Adapter fill,get methods.
when i tried to pass the date value which in "MM/dd/yyyy"
it raises error message invalid datetime,then
i declared DateTime variable and use Datetime.Parse(date in "MM/dd/yyyy"),
DateTime.Parseexact,error not a valid datetime. i use Culture info ("en-US"),but no luck.
|
|
|
|
|
|
I hope you are NOT storing your date values as varchar in the database, you would be committing a major offence doing that.
I use paramerterised queries and pass a date type into the sp. If I have to pass a string of a date to a proc I use 106 = "dd MMM yyyy" there is NO ambiguity in that format.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|