Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I would like to create a windows form using Visual Studio 2013 (C#) that will load and display up to 5 different files. Each file has 16 sections that need to be displayed separately. Once all 5 files are loaded, I would like to create a new file based on dragging and dropping sections from the 5 files in the order they where dragged and dropped.

File sizes are under 1MB and have each section has a fixed address range.

What would be the best way to achieve this in a windows form?

Right now I'm achieving this by using checked list boxes, but it does not give me the flexibility the above description would. Thank you for any help in advance.

***Update***
Thank you for the responses.

The files are normally viewed in a hex editor, so the actual data does not need to be seen in a text window. Just the 16 individual fixed address ranges, like an item in a list box.

Is it possible to drag and drop an item from one list box to another?
Posted
Updated 30-Mar-14 5:22am
v2
Comments
PIEBALDconsult 29-Mar-14 13:30pm    
Would all the sections be used?
CHill60 29-Mar-14 13:33pm    
Is the user going to determine this order or is it fixed?

Something that comes to mind is to have a TabPage for each section. Allow the user to reorder the tabs as desired and close any undesired tabs. Then a Save operation would save the contents of the tabs to a file in whatever order they are. Done.
 
Share this answer
 
v2


Assumptions:



  1. All sections of all five files are to be displayed at once.
  2. A section may not be moved twice.
  3. When a section is dragged, it will be placed in the "target" area consecutively (i.e., order of dragged sections is in the order dragged).


I'd use two RichTextBoxes side-by-side to display the sections. The RichTextBox on the left contains the source sections; that on the right the selected sections. I would set off each file with some type of enclosing box (say, blue-dotted) and each section with a different type of enclosing box (say green-dotted).



I've used this type of GUI in Transfer and XFR Tools - Extensions [^] (see Extensions) and found it easy to implement. Note that the left and right containers in that article are ListBoxes not RichTextBoxes.



When the use clicks within a section, I'd change the shape of the cursor and the background color of the section box. Note you will need to handle MouseDown, MouseUp, and MouseMove events.



When the user releases the mouse button, and the mouse position is within the target RichTextBox, copy the contents of the source section box to the new target section box. (Initially, when moving the cursor, just show the cursor; later when everything works as desired, you can become more flashy by dragging the chosen section box and its contents as the cursor is moved).



Signal that a section has been moved by simply removing the contents of the source section and marking the section as immovable. Alternately, you could just remove the section entirely.

 
Share this answer
 
v2
Comments
PIEBALDconsult 29-Mar-14 14:29pm    
How do you implement undo? Or otherwise allow the user to change his mind?
gggustafson 29-Mar-14 15:08pm    
The OP did not ask that. However, undoing could be a simple matter of dragging the section to be undone back to the source area. Here we assume that the source file and source section identities are maintained with the target sections.

Alternatively, a more complicated procedure would be to have an undo button that becomes enabled when a section in the target area is selected.
PIEBALDconsult 29-Mar-14 16:00pm    
"dragging the section to be undone back to the source area"

I don't see how one would do that in a RichTextBox.
gggustafson 29-Mar-14 16:07pm    
Are you asking me to supply an actual solution (i.e., code)?
PIEBALDconsult 29-Mar-14 17:00pm    
Frack no.
I would create a Form like this:

1. one horizontal split-container docked full, 'HSplit1

2. in the left panel of #1 a TreeView Control docked full, 'DocTreeView

3. in the right panel of #1 another horizontal split-container, 'HSplt2

4. in the left panel of #2 a TextBox docked full, 'SourceTextBox

5. in the right panel of #2 a TextBox docked full, 'DestinationTextBox

I would set-up the TreeView like this:

1. give the user some interface to select up to five files

2. add a root node for each file

3. parse each file to determine the sections

4. create child-nodes for each root-node internally linked to the sections of each file

The run-time behavior of the program: assuming the TreeView is filled properly

1. the user clicks on a root-node (file), and selects a section (child-node)

2. the text associated with that section is displlayed in the 'SourceTextBox

3. the user can select Text in the 'SourceTextBox and drag-drop it into the 'DestinationTextBox.

4. the Application would provide some useful interface for saving the contents of the 'DestinationTextBox, for changing the currently opened source files, rebuilding the TreeView, etc.

Notes:

1. The difficulty with drag-dropping from one TextBox (or RichTextBox) to another is that a mouse-down (default mouse-down) on the current selection will cause the selection to be cleared. To get around this: you need to use techniques like:

a. don't call 'DoDragDrop in the MouseDown unless the context-click mouse button is down; example:
C#
private void SourceTextBox_MouseDown(object sender, MouseEventArgs e)
{
    if (MouseButtons == MouseButtons.Right)
    {
        SourceTextBox.DoDragDrop(SourceTextBox.SelectedText, DragDropEffects.Copy);
    }
}
b. use a modified WndProc and an over-ride of 'OnMouseDown; see: [^].

2. Why use horizontal splitters ? Answer: for the user's convenience in using the UI.

If you have further questions, please feel free to ask.
 
Share this answer
 
v4
Comments
JoshK1 30-Mar-14 14:44pm    
I'm not sure if any update is sent out if the original question is updated.

The files are normally viewed in a hex editor, so the actual data does not need to be seen in a text window. Just the 16 individual fixed address ranges, like an item in a list box.

Is it possible to drag and drop an item from one list box to another?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900