PC Review


Reply
Thread Tools Rate Thread

How do I place card so each added card overlap in the way I want

 
 
Tony Johansson
Guest
Posts: n/a
 
      15th Mar 2011
Hello

Here is some code that place a user control called CardGUI in another user
control named PlayerGUI.
Assume width for the CardGUI is 100. The first card is placed at xPos=0 and
y=0.
Now when I place the second card I set xPos = 50 and y = 0.
The problem is that I want the second card to overlap the first so only the
left part of the first card is shown.
I thought this code did this but here only the right part the second card
that is shown.

private void InitialDeal()
{
Control[] ctrl = this.pnlPlayers.Controls.Find(PlayerGUI, false);

for (int cardNr = 0; cardNr < StartDeal; cardNr++)
{
for (int playerNr = 0; playerNr < ctrl.Length; playerNr++)
{
Card card = gm.GetPlayerCard(playerNr, cardNr);
for (int i = 0; i < pnlPlayers.Controls.Count; i++)
{
PlayerGUI pg = ctrl[i] as PlayerGUI;
if (pg.PlayerName == gm.Players[playerNr].Name)
{
string imagePath =
Path.Combine(Environment.CurrentDirectory, @"..\..\Images\" + card.Suit+
".ico");
CardGUI cg = new CardGUI(imagePath,card.RankSymbol());

int xPos = (cardNr % 2) * cg.Width/2;
cg.Location = new Point(xPos, 0);
pg.AddCard(cg);
break;
}
}
}
}
}

//Tony


 
Reply With Quote
 
 
 
 
Tony Johansson
Guest
Posts: n/a
 
      16th Mar 2011

"Peter Duniho" <(E-Mail Removed)> skrev i meddelandet
news:HfednRoGnoLf-(E-Mail Removed)...
> On 3/15/11 4:17 PM, Tony Johansson wrote:
>> Hello
>>
>> Here is some code that place a user control called CardGUI in another
>> user
>> control named PlayerGUI.
>> Assume width for the CardGUI is 100. The first card is placed at xPos=0
>> and
>> y=0.
>> Now when I place the second card I set xPos = 50 and y = 0.
>> The problem is that I want the second card to overlap the first so only
>> the
>> left part of the first card is shown.
>> I thought this code did this but here only the right part the second card
>> that is shown.

>
> Google "z-order". In .NET, BringToFront() and SendToBack() can help you
> manage this.


This BringToFront on my user control CardGUI does not bring that control to
front it is still in the back.
I have a panel that I put these user control in and I always want the last
added control to be in the front.
I have read the docs and it doesn't say any strange about this. It says
"The control is moved to the front of the z-order. If the control is a child
of another control, the child control is moved to the front of the z-order.
BringToFront does not make a control a top-level control, and it does not
raise the Paint event."
I don't get any kind of error it just don't do what I have told it to do
which is bring the control in front.

Have I missed something here ?

//Tony


 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      17th Mar 2011

"Peter Duniho" <(E-Mail Removed)> skrev i meddelandet
news:R7-(E-Mail Removed)...
> On 3/16/11 8:02 AM, Tony Johansson wrote:
>> [...]
>> Have I missed something here ?

>
> Definitely. But since you haven't bothered to post a concise-but-complete
> code example that reliably reproduces the problem, well.you know the rest.
>
> Pete


Here is complete example where I use Button and it doesn't work as expected.
As you can see in the code I first put one button in the panel with a text
First and then
I put a second button in the panel with a text Second. This second Button is
positioned a litte bit to the right
from the first button. I use BringTofront to make the last button the
topmost but instead it will be put under the first button so the first
button is always the topmost
Is this perhaps a bug because it doesn't work as it should ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Slask
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

for (int i = 0; i <= 1; i++)
{
Button btn = new Button();

int xPos = (i % 2) * btn.Width / 2;
btn.Location = new Point(xPos, 0);
btn.BringToFront();
if (i == 0)
btn.Text = "First";
else
btn.Text = "Second";

panel1.Controls.Add(btn);
}
}
}

partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(12, 26);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(268, 197);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 270);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}

#endregion

private System.Windows.Forms.Panel panel1;
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

//Tony


 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      17th Mar 2011
"Tony Johansson" <(E-Mail Removed)> wrote in message
news:ilst84$55f$(E-Mail Removed)...

> for (int i = 0; i <= 1; i++)
> {
> Button btn = new Button();
>
> int xPos = (i % 2) * btn.Width / 2;
> btn.Location = new Point(xPos, 0);
> btn.BringToFront();
> if (i == 0)
> btn.Text = "First";
> else
> btn.Text = "Second";
>
> panel1.Controls.Add(btn);


I have only glanced at this, but I'm virtually positive that your call to
BringToFront() is useless as-is. The button as not been given a parent yet;
this doesn't happen until you call panel1.Controls.Add(). BringToFront()
only works with sibling controls, i.e., controls with the same parent. So if
the button has no parent, what controls is it supposed to be brought to the
front of?


 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      17th Mar 2011

"Jeff Johnson" <(E-Mail Removed)> skrev i meddelandet
news:ilt58p$1ti$(E-Mail Removed)...
> "Tony Johansson" <(E-Mail Removed)> wrote in message
> news:ilst84$55f$(E-Mail Removed)...
>
>> for (int i = 0; i <= 1; i++)
>> {
>> Button btn = new Button();
>>
>> int xPos = (i % 2) * btn.Width / 2;
>> btn.Location = new Point(xPos, 0);
>> btn.BringToFront();
>> if (i == 0)
>> btn.Text = "First";
>> else
>> btn.Text = "Second";
>>
>> panel1.Controls.Add(btn);

>
> I have only glanced at this, but I'm virtually positive that your call to
> BringToFront() is useless as-is. The button as not been given a parent
> yet; this doesn't happen until you call panel1.Controls.Add().
> BringToFront() only works with sibling controls, i.e., controls with the
> same parent. So if the button has no parent, what controls is it supposed
> to be brought to the front of?


Yes you are right I just move this row
btn.BringToFront();
after this row
panel1.Controls.Add(btn);
and now it works.

Many thanks

//Tony


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wedding place card printing??? NEED HELP! adamopsu Microsoft Word Document Management 1 2nd Jun 2008 07:27 PM
Appreciation card for the work place =?Utf-8?B?U2FtYW50aGE=?= Microsoft Word Document Management 3 28th Feb 2007 09:08 PM
My memory is not increased when I added my sd ram card. =?Utf-8?B?ZWZtZWRpYQ==?= Windows XP Performance 1 7th Sep 2004 08:41 PM
Added wireless card Brandi Microsoft Windows 2000 Networking 2 9th Aug 2004 08:44 PM
network card all dressed up with no place to go Amy Windows XP Hardware 6 15th Jun 2004 04:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:21 PM.