Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
GeneralOwnerDraw PropertyGrid Pin
Shane Stevens22-Aug-05 15:51
Shane Stevens22-Aug-05 15:51 
GeneralTotal newb needs help. Pin
tomlog22-Aug-05 14:16
tomlog22-Aug-05 14:16 
GeneralRe: Total newb needs help. Pin
Christian Graus22-Aug-05 14:31
protectorChristian Graus22-Aug-05 14:31 
GeneralRe: Total newb needs help. Pin
tomlog23-Aug-05 6:30
tomlog23-Aug-05 6:30 
GeneralRe: Total newb needs help. Pin
Christian Graus23-Aug-05 13:27
protectorChristian Graus23-Aug-05 13:27 
GeneralProblem getting drag and drop to work between listbox with mode set to MultiExtended Pin
22-Aug-05 13:04
suss22-Aug-05 13:04 
GeneralRe: Problem getting drag and drop to work between listbox with mode set to MultiExtended Pin
Luis Alonso Ramos22-Aug-05 18:58
Luis Alonso Ramos22-Aug-05 18:58 
GeneralRe: Problem getting drag and drop to work between listbox with mode set to MultiExtended Pin
Member 221063323-Aug-05 12:34
Member 221063323-Aug-05 12:34 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

namespace WindowsTestApp
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private Point m_mouseDownPoint;
private int m_currentIndex;

private System.Windows.Forms.Button btnTest;
private System.Windows.Forms.ListBox lstTest_1;
private System.Windows.Forms.ListBox lstTest_2;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.lstTest_1 = new System.Windows.Forms.ListBox();
this.btnTest = new System.Windows.Forms.Button();
this.lstTest_2 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// lstTest_1
//
this.lstTest_1.AllowDrop = true;
this.lstTest_1.Items.AddRange(new object[] {
"Line 1",
"Line 2",
"Line 3",
"Line 4"});
this.lstTest_1.Location = new System.Drawing.Point(32, 24);
this.lstTest_1.Name = "lstTest_1";
this.lstTest_1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstTest_1.Size = new System.Drawing.Size(120, 95);
this.lstTest_1.TabIndex = 0;
this.lstTest_1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstTest_1_MouseDown);
this.lstTest_1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lstTest_1_MouseMove);
//
// btnTest
//
this.btnTest.Location = new System.Drawing.Point(96, 136);
this.btnTest.Name = "btnTest";
this.btnTest.Size = new System.Drawing.Size(120, 23);
this.btnTest.TabIndex = 1;
this.btnTest.Text = "Test";
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// lstTest_2
//
this.lstTest_2.AllowDrop = true;
this.lstTest_2.Items.AddRange(new object[] {
"Line 1",
"Line 2",
"Line 3",
"Line 4"});
this.lstTest_2.Location = new System.Drawing.Point(168, 24);
this.lstTest_2.Name = "lstTest_2";
this.lstTest_2.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstTest_2.Size = new System.Drawing.Size(120, 95);
this.lstTest_2.TabIndex = 2;
this.lstTest_2.DragOver += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragOver);
this.lstTest_2.DragDrop += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragDrop);
this.lstTest_2.DragEnter += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragEnter);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(304, 182);
this.Controls.Add(this.lstTest_2);
this.Controls.Add(this.btnTest);
this.Controls.Add(this.lstTest_1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btnTest_Click(object sender, System.EventArgs e)
{
Debug.WriteLine("btnTest_Click::Start");

WriteSelectedItems(lstTest_1);
}

private void lstTest_2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("lstTest_2_DragDrop::Start");

WriteSelectedItems(lstTest_1);
}

private void lstTest_2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("lstTest_2_DragEnter::Start");

// If the data is text, allow data to copied the ListBox control
if(e.Data.GetDataPresent("Text"))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}

private void lstTest_2_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
// Retrieve the line at the specified location within the ListBox
Point pt = new Point(e.X, e.Y);
m_currentIndex = lstTest_2.IndexFromPoint(lstTest_2.PointToClient(pt));
}

private void lstTest_1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Debug.WriteLine("lstTest_1_MouseDown::Start");

m_mouseDownPoint = new Point(e.X, e.Y);
}

private void lstTest_1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
// We know the mouse is down - has it moved enough to consider it a drag?
Size dragBoxSize = SystemInformation.DragSize;

if((dragBoxSize.Width > Math.Abs(m_mouseDownPoint.X - e.X)) || (dragBoxSize.Height > Math.Abs(m_mouseDownPoint.Y - e.Y)))
{
Debug.WriteLine("lstTest_1_MouseMove::Start - Drag started");

WriteSelectedItems(lstTest_1);

// We should consider this a drag ...
lstTest_1.DoDragDrop("Test", DragDropEffects.Copy);
}
}
}

private void WriteSelectedItems(ListBox lst)
{
Debug.WriteLine("WriteSelectedItems::Start");
Debug.WriteLine("WriteSelectedItems: count=" + lst.SelectedIndices.Count);

for(int i = 0; i < lst.SelectedIndices.Count; i++)
{
try
{
Debug.WriteLine(lst.SelectedIndices[i] + "=" + lst.SelectedItems[i]);
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Exception caught: {0}", e);
}
}
}

}
}
Generalcomparing computation Pin
Sasuko22-Aug-05 12:57
Sasuko22-Aug-05 12:57 
GeneralRe: comparing computation Pin
Christian Graus22-Aug-05 13:04
protectorChristian Graus22-Aug-05 13:04 
Generaladding 2 buttons to a data grid Pin
Member 221087122-Aug-05 11:56
Member 221087122-Aug-05 11:56 
GeneralRe: adding 2 buttons to a data grid Pin
Christian Graus22-Aug-05 12:07
protectorChristian Graus22-Aug-05 12:07 
GeneralRe: adding 2 buttons to a data grid Pin
Member 221087122-Aug-05 13:37
Member 221087122-Aug-05 13:37 
GeneralRe: adding 2 buttons to a data grid Pin
Christian Graus22-Aug-05 13:57
protectorChristian Graus22-Aug-05 13:57 
GeneralRe: adding 2 buttons to a data grid Pin
Member 221087122-Aug-05 15:58
Member 221087122-Aug-05 15:58 
GeneralCould you please... Pin
KORCARI22-Aug-05 10:53
KORCARI22-Aug-05 10:53 
GeneralRe: Could you please... Pin
Christian Graus22-Aug-05 10:57
protectorChristian Graus22-Aug-05 10:57 
GeneralRe: Could you please... Pin
KORCARI22-Aug-05 18:01
KORCARI22-Aug-05 18:01 
GeneralRe: Could you please... Pin
Christian Graus22-Aug-05 18:23
protectorChristian Graus22-Aug-05 18:23 
QuestionHow to pass variables through URL in CGI Pin
Handy Su22-Aug-05 10:51
Handy Su22-Aug-05 10:51 
AnswerRe: How to pass variables through URL in CGI Pin
Handy Su22-Aug-05 10:58
Handy Su22-Aug-05 10:58 
GeneralCalling a function from Intel Library using C# Pin
E6AD22-Aug-05 10:11
E6AD22-Aug-05 10:11 
GeneralRe: Calling a function from Intel Library using C# Pin
Judah Gabriel Himango22-Aug-05 10:49
sponsorJudah Gabriel Himango22-Aug-05 10:49 
GeneralRe: Calling a function from Intel Library using C# Pin
E6AD22-Aug-05 12:21
E6AD22-Aug-05 12:21 
GeneralRe: Calling a function from Intel Library using C# Pin
Judah Gabriel Himango22-Aug-05 17:03
sponsorJudah Gabriel Himango22-Aug-05 17:03 

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.