PDA

View Full Version : Delete selected button(s)


MZ
05-17-2011, 04:21 PM
------------code start-------------
destroydialog TestRoll

rollout TestRoll "Characters" width:570 height:560
(
button btn_delete "Delete Selected Button" width:50 height:20
dotNetControl flp_FLP "flowLayoutPanel" width:550 height:530
ON TestRoll OPEN DO
(
flp_FLP.autoScroll = true

global buttons = for i=1 to 10 collect
(
b = dotNetObject "Button"
b.text = (i as string)
b.size = dotNetObject "System.Drawing.Size" 100 100
flp_FLP.controls.add b
b
)

)
on btn_delete pressed do
(
-- i want to delete selected button
)
)
createdialog TestRoll


----------end code-----------------------
How i can delete selected button?

denisT
05-17-2011, 04:37 PM
how does selected button looks like? ;)
is it a button that has the focus? usually it's the last clicked button. do you want to delete the button that you've clicked?

why to delete? you can change the button's functionality, hide the button, disable...
whatever... to delete System.Windows.Forms.Button use its Dispose method.

MZ
05-17-2011, 07:46 PM
i want to use this button (delete) in my Assetbrowser,
my Assetbrowser shows max files thumbnail, when i click on delete button , selected thumbnail will be removed from panel and max file will be deleted and flowlayout panel will be rearranged.but problem is when i click on delete button,selected thumbnail will be deselected or unfocussed so event handler cant find selected button.
sorry im just an 3dartist with bad english!
really i have three question:
1-you say i can access last clicked button. how?
2- how i can remove all controls in flowlayout panel?
3-how i can move or relocation buttons?

Light
05-17-2011, 09:31 PM
Hi,

Just store a reference to a button as soon as it's clicked on. You could use the same event handler and do something like:

fn ButtonClicked sender e =
(
LastClickedButton = sender
)





Light

MZ
05-17-2011, 10:27 PM
TankYou Light,
can you answer other questions?
2-how i can remove all controls in flowlayout panel?
3-how i can move or relocation buttons?
4-how i can use Alt or Shift or Ctrl with RMB or LMB in "click" eventhandler?

Light
05-17-2011, 10:41 PM
1. flowLayoutControl.Controls.Clear();
2. button.Location = new Point (x, y);
3. You have to use the KeyDown/KeyUp events to record the button states you want, and then clear it when the key is released.




Light

denisT
05-17-2011, 10:53 PM
i want to use this button (delete) in my Assetbrowser,
my Assetbrowser shows max files thumbnail, when i click on delete button , selected thumbnail will be removed from panel and max file will be deleted and flowlayout panel will be rearranged.but problem is when i click on delete button,selected thumbnail will be deselected or unfocussed so event handler cant find selected button.
sorry im just an 3dartist with bad english!
really i have three question:
1-you say i can access last clicked button. how?
2- how i can remove all controls in flowlayout panel?
3-how i can move or relocation buttons?

there are some advices:
1) try to use most appropriate control for your tasks... for your current task it's probably ListView or DataGridView
2) if you want to stay with buttons solution use Button's Checked state (not focus)
3) keep tracking of selected items inside your code

answers:
1. you are talking not about last clicked but about previously clicked control. it's possible to get it, but how can it help you? it might not be a button from your FlowLayoutPanel, it can be any window.

2. to remove all buttons you have to go though all controls of their parent (FlowLayoutPanel in your case) and dispose every button in collection.

3. to move any control use its Location property

denisT
05-17-2011, 10:56 PM
1. flowLayoutControl.Controls.Clear();
...

actually Clear doesn't delete child controls. it just removes them from collection.

Light
05-17-2011, 11:05 PM
actually Clear doesn't delete child controls. it just removes them from collection.

I thought he wanted to remove them from the FlowLayoutPanel.




Light

denisT
05-17-2011, 11:14 PM
I thought he wanted to remove them from the FlowLayoutPanel.




Light

you are right. it removes buttons from panel. but it doesn't free resources (button itself, bitmap, event handlers, etc.). actually MZ has to clear what he wants. maybe to keep resources is a better idea.

MZ
05-17-2011, 11:51 PM
there are some advices:
1) try to use most appropriate control for your tasks... for your current task it's probably ListView or DataGridView
2) if you want to stay with buttons solution use Button's Checked state (not focus)
3) keep tracking of selected items inside your code

answers:
1. you are talking not about last clicked but about previously clicked control. it's possible to get it, but how can it help you? it might not be a button from your FlowLayoutPanel, it can be any window.

2. to remove all buttons you have to go though all controls of their parent (FlowLayoutPanel in your case) and dispose every button in collection.

3. to move any control use its Location property

ok,i will check ListView and DataGridView later.
look at this code:
---------------------codestart---------------

rollout testRoll "TEST" width:500 height:500
(
button btn_Delete "Delete" pos:[13,5] width:70 height:50
dotNetControl flp_testFLP "flowLayoutPanel" width:480 height:200
dotNetControl flp_testFLP2 "flowLayoutPanel" width:480 height:200
ON testRoll OPEN DO
(
flp_testFLP.autoScroll = true

fn onClick s e =
(
Lastclickedbutton = s
)
buttons = for i=1 to 5 collect
(
b = dotNetObject "Button"
b.text = "(Deleteable)"+(i as string)
b.size = dotNetObject "System.Drawing.Size" 100 100
b.location = dotNetObject "System.Drawing.Point" (i*50) 0
dotnet.addEventHandler b "Click" onClick
flp_testFLP.controls.add b
b
)

buttons2 = for i=1 to 5 collect
(
b = dotNetObject "Button"
b.text = "(NoDelete)"+(i as string)
b.size = dotNetObject "System.Drawing.Size" 100 100
b.location = dotNetObject "System.Drawing.Point" (i*50) 0
dotnet.addEventHandler b "Click" onClick
flp_testFLP2.controls.add b
b
)
)

on btn_Delete pressed do
(
try (flp_testFLP.controls.remove Lastclickedbutton)catch()
--Remove Max File from Folder
)
)
createDialog testRoll
----------------------endcode------------------------------
removing button from FLP1 don't effect other FLP2
goal of MyAssetbrowser is collecting maxfile addresses and show its thumbnails.by clicking on thumbnail max file will be merge.
by changing address, i have to update buttons,so i think you right.loop throw FLP controls and dispose() them is good idea.i need to remove all buttons and recreate them.

MZ
05-18-2011, 12:24 AM
there is a way to multiselect buttons?

MZ
05-21-2011, 02:08 PM
Tank you Denis,ListView was useful but i have 2 question
1- how i can decrease space between listview items (thumbnails)?
2- listview item are flat! there is a way to make border like buttons?

denisT
05-21-2011, 06:53 PM
there is a way to multiselect buttons?

that's exactly why i suggested to use some build-in control (datagridview, listview, etc.)

ListView was useful but i have 2 question
1- how i can decrease space between listview items (thumbnails)?
2- listview item are flat! there is a way to make border like buttons?

1. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.tilesize.aspx
2. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw.aspx

MZ
06-05-2011, 08:00 PM
there is a way to control autoscroll position or value?(in panel)

CGTalk Moderation
06-05-2011, 08:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.