Click here to Skip to main content
15,899,474 members
Home / Discussions / C#
   

C#

 
AnswerRe: help me Pin
Nader Elshehabi6-Sep-06 1:03
Nader Elshehabi6-Sep-06 1:03 
QuestionCustom Button Pin
NaveenReddy.Rv5-Sep-06 23:32
NaveenReddy.Rv5-Sep-06 23:32 
AnswerRe: Custom Button Pin
Amar Chaudhary5-Sep-06 23:45
Amar Chaudhary5-Sep-06 23:45 
AnswerRe: Custom Button Pin
mikone5-Sep-06 23:49
mikone5-Sep-06 23:49 
AnswerRe: Custom Button Pin
Nader Elshehabi6-Sep-06 1:29
Nader Elshehabi6-Sep-06 1:29 
QuestionADO.NET related question Pin
Imtiaz Murtaza5-Sep-06 22:43
Imtiaz Murtaza5-Sep-06 22:43 
AnswerRe: ADO.NET related question Pin
Ravi Bhavnani6-Sep-06 1:07
professionalRavi Bhavnani6-Sep-06 1:07 
QuestionWhat format is the best for a procedure? Pin
steed leung5-Sep-06 22:17
steed leung5-Sep-06 22:17 
The time that I write code is not long, so I always confuse about what format should be the best for a procedure. In a case, if you write the code with the general thinking, maybe in the procedure it will have some repetitious use of some judge conditions or the calling of a sub_function. If you do this procedure with a unusual thinking, maybe the procedure can avoid the repetitions use. But ,it will make other people who read your code not quitely easy to understand. In this case, What way to write the code is the best one?
Following is my code of Drag&Drop for two listBox. The fucntion is :when two listbox in a form, user can drag left listbox item to right listbox which adds the item; and the right listbox items can Drag&Drop up and down.
General thinking is: First- DO left listbox's Drag&Drop action; Second- Do right listbox's Drag&Drop action. But this way should make the repetitious use of judge conditions or sub_fuction.With the way of my thinking, it can decrease the repetition.

//the Drag&Drop event
  private void listBoxUCP_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
{

object item = e.Data.GetData(typeof(System.String));

// Perform drag-and-drop, depending upon the effect.
if (e.Effect == DragDropEffects.Move)
{
updateListBoxItems(source, listBoxUCP, item, e);
}
}
}
    
    //sub_procedure
    private void updateListBoxItems(ListBox sourceListBox, ListBox targetListBox, object sourceItem, DragEventArgs e)
{
int targetIndex = getTartgetIndexFromPoint(targetListBox, e);
int sourceIndex = targetListBox.SelectedIndex;

if (sourceListBox == targetListBox)
{
if (targetIndex == targetListBox.SelectedIndex)
return;
targetListBox.Items.RemoveAt(sourceIndex);
}
      //if target listboxItem != null and insert place not in the end of the itemlist,
//use the insert method
if (targetIndex > 0 && targetIndex < targetListBox.Items.Count)
{
if (sourceListBox != targetListBox || sourceIndex > targetIndex)
targetIndex = targetIndex + 1;

targetListBox.Items.Insert(targetIndex, sourceItem);
targetListBox.SelectedIndex = targetIndex;

}
// else add the item in the end of the itemlist
else
{
targetListBox.Items.Add(sourceItem);
targetListBox.SelectedIndex = targetListBox.Items.Count - 1;
}
}

    private int getTartgetIndexFromPoint(ListBox listBox, DragEventArgs e)
{
Point position = new Point(e.X, e.Y);
position = listBox.PointToClient(position);
return listBox.IndexFromPoint(position);
}

Can somebody tell me the defect of my code? You think what format is the best one of this function!
Thanks for any proposals!Laugh | :laugh:
AnswerRe: What format is the best for a procedure? Pin
Nader Elshehabi6-Sep-06 1:14
Nader Elshehabi6-Sep-06 1:14 
AnswerRe: What format is the best for a procedure? Pin
steed leung6-Sep-06 16:38
steed leung6-Sep-06 16:38 
QuestionCrystal Report Redistributable - Not Pin
Glen Harvy5-Sep-06 22:06
Glen Harvy5-Sep-06 22:06 
AnswerRe: Crystal Report Redistributable - Not Pin
Aaron Dilliard6-Sep-06 9:33
Aaron Dilliard6-Sep-06 9:33 
GeneralRe: Crystal Report Redistributable - Not Pin
Glen Harvy6-Sep-06 12:11
Glen Harvy6-Sep-06 12:11 
GeneralRe: Crystal Report Redistributable - Not Pin
c#guy38116-Sep-06 17:20
c#guy38116-Sep-06 17:20 
QuestionThe type or namespace name 'rtbText' could not be found (are you missing a using directive or an assembly reference?) Pin
Kyle Bartolo5-Sep-06 22:00
Kyle Bartolo5-Sep-06 22:00 
AnswerRe: The type or namespace name 'rtbText' could not be found (are you missing a using directive or an assembly reference?) Pin
mikone5-Sep-06 23:25
mikone5-Sep-06 23:25 
AnswerRe: The type or namespace name 'rtbText' could not be found (are you missing a using directive or an assembly reference?) Pin
Nader Elshehabi6-Sep-06 1:34
Nader Elshehabi6-Sep-06 1:34 
Questionhow to add C++ code in CSharp Programming Pin
phijophlip5-Sep-06 22:00
phijophlip5-Sep-06 22:00 
AnswerRe: how to add C++ code in CSharp Programming Pin
erfi5-Sep-06 23:36
erfi5-Sep-06 23:36 
AnswerRe: how to add C++ code in CSharp Programming Pin
Nader Elshehabi6-Sep-06 2:06
Nader Elshehabi6-Sep-06 2:06 
Questionplz help me,i want to send/receive data to one hardware device that is conneted with GPIB cable , how can i send data to that device in C#.net Pin
premkamalg5-Sep-06 21:58
premkamalg5-Sep-06 21:58 
AnswerRe: plz help me,i want to send/receive data to one hardware device that is conneted with GPIB cable , how can i send data to that device in C#.net Pin
Nader Elshehabi6-Sep-06 2:33
Nader Elshehabi6-Sep-06 2:33 
Questiond Pin
penecilllin5-Sep-06 21:49
penecilllin5-Sep-06 21:49 
AnswerRe: the ~ operator preceding constructor Pin
ejuanpp5-Sep-06 22:14
ejuanpp5-Sep-06 22:14 
AnswerRe: the ~ operator preceding constructor Pin
Guffa6-Sep-06 0:34
Guffa6-Sep-06 0:34 

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.