Click here to Skip to main content
16,004,882 members
Home / Discussions / C#
   

C#

 
QuestionRe: Drawing then adding to a page Pin
Expert Coming25-Feb-07 17:59
Expert Coming25-Feb-07 17:59 
AnswerRe: Drawing then adding to a page Pin
NanaAM25-Feb-07 18:25
NanaAM25-Feb-07 18:25 
QuestionRe: Drawing then adding to a page Pin
Expert Coming25-Feb-07 18:28
Expert Coming25-Feb-07 18:28 
AnswerRe: Drawing then adding to a page Pin
NanaAM25-Feb-07 19:05
NanaAM25-Feb-07 19:05 
GeneralRe: Drawing then adding to a page Pin
Expert Coming25-Feb-07 19:09
Expert Coming25-Feb-07 19:09 
GeneralRe: Drawing then adding to a page Pin
NanaAM25-Feb-07 19:39
NanaAM25-Feb-07 19:39 
GeneralRe: Drawing then adding to a page Pin
Expert Coming25-Feb-07 19:43
Expert Coming25-Feb-07 19:43 
QuestionCircular control reference... [modified] Pin
new_phoenix25-Feb-07 14:41
new_phoenix25-Feb-07 14:41 
I am working on an application that is a card based computer game. In the application there are playing cards made out of controls, and each of the control is an element of a control array. Each of the cards must be able to be a child to another card and/or a parent control to another card.

This creates a situation in which any control could be dragged onto another control based upon compliance with the rules of the game. However, the problem occurs when there is the capability to drag a parent control onto an already placed child control.

Here is the problem. When a child is dragged onto its parent control it generates the error: "A circular control reference has been made. A control cannot be owned or parented to itself."

How do I resolve this circular control reference or completely prevent the possibility of a child control from being dragged onto its parent in the first place?

The code for the DragOver event for each of the controls is as follows:

/// <summary>
/// Handles the parent receiving a DragOver event
/// </summary>
/// <param name="sender">The parent receiving the event</param>
/// <param name="e">Contains the data being dragged</param>
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{
    try
    {
        // If this is a valid control for this parent, allow it to move
        // freely over, otherwise disallow DragDrop operations
        if ( DragDropHandler.CanDropHere((Control)sender, e.Data) )
        {
            // cthis... this as a Control
            Control cthis = (Control)sender;

            // Set the DragDropEffect and get the control we are dragging
            e.Effect = DragDropEffects.Move;
            Control ctrl = DragDropHandler.GetControl(e.Data, true, true);

            // If this isn't an IDragDropEnabled control don't worry about
            // showing it's position
            if (!(ctrl is IDragDropEnabled))
            {
                return;
            }

            // If this control is not part of the current "parent"
            // remove it from it's original parent and place it in
            // the current parent control collection
            if (cthis.Name != ctrl.Name)  // attempts to test for controls without the same name.
            {
                ctrl.Parent.Controls.Remove(ctrl);
                ctrl.Parent = cthis;
                cthis.Controls.Add(ctrl);
                ctrl.BringToFront();

                Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y));
                ctrl.Left = NewLocation.X - dragPoint.X;
                ctrl.Top = NewLocation.Y - dragPoint.Y;
            }
            else
            {
                return;
            }
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error is " + ex.Message);
    }
}


NOTE: When the child control is dragged onto the parent control, both controls disappear from the screen because of the circular reference error generated. How is a test performed to prevent a circular reference when it is necessary to have the potential to be both a child and a parent control?


-- modified at 20:50 Sunday 25th February, 2007
QuestionListview - Changing the Column Header colours Pin
Glen Harvy25-Feb-07 12:22
Glen Harvy25-Feb-07 12:22 
QuestionC# Reading/Writing XML Pin
Planker25-Feb-07 10:29
Planker25-Feb-07 10:29 
AnswerRe: C# Reading/Writing XML Pin
Christian Graus25-Feb-07 11:05
protectorChristian Graus25-Feb-07 11:05 
QuestionC# code Algorithms ready to copy and paste. Pin
Underhillron25-Feb-07 9:45
Underhillron25-Feb-07 9:45 
AnswerRe: C# code Algorithms ready to copy and paste. Pin
User 171649225-Feb-07 12:48
professionalUser 171649225-Feb-07 12:48 
AnswerRe: C# code Algorithms ready to copy and paste. Pin
Binod K25-Feb-07 19:48
Binod K25-Feb-07 19:48 
Question[C#] Add dll [modified] Pin
abbd25-Feb-07 9:14
abbd25-Feb-07 9:14 
AnswerRe: [C#] Add dll Pin
Guffa25-Feb-07 9:25
Guffa25-Feb-07 9:25 
GeneralRe: [C#] Add dll Pin
abbd25-Feb-07 11:11
abbd25-Feb-07 11:11 
GeneralRe: [C#] Add dll Pin
Dave Kreskowiak25-Feb-07 12:41
mveDave Kreskowiak25-Feb-07 12:41 
AnswerRe: [C#] Add dll Pin
Christian Graus25-Feb-07 11:56
protectorChristian Graus25-Feb-07 11:56 
QuestionHow to Fire TabControl? Pin
Khoramdin25-Feb-07 9:04
Khoramdin25-Feb-07 9:04 
AnswerRe: How to Fire TabControl? Pin
Martin#25-Feb-07 11:10
Martin#25-Feb-07 11:10 
Question[Message Deleted] Pin
Zealous_Me25-Feb-07 8:14
Zealous_Me25-Feb-07 8:14 
AnswerRe: this question twisted me. Pin
Christian Graus25-Feb-07 8:51
protectorChristian Graus25-Feb-07 8:51 
AnswerRe: this question twisted me. Pin
Colin Angus Mackay25-Feb-07 9:01
Colin Angus Mackay25-Feb-07 9:01 
QuestionProducer/Consumer & locking mechanisms... Pin
Shy Agam25-Feb-07 3:31
Shy Agam25-Feb-07 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.