|
Design patterns will help you structure your code.
However, if you write good code, you could probably do without design patters.
Remember a few basics like high cohesion and low coupling.
|
|
|
|
|
As you can use a delegate to set the value of a property, you can obviously use a multicast delegate to set the properties of a class.
Or you can use a binding.
What are the pros and cons of each method?
|
|
|
|
|
Delegates and (data) binding are useful in different circumstances.
Although, both can be used to change property values at runtime, multicast delegates are useful when you want to invoke multiple operations (rather than bind data) at runtime. Binding on the other hand is useful to directly set the values of properties at runtime. Binding a property to a value will not help you execute methods.
|
|
|
|
|
They are two distinct ways of communicating between entities, although you can implement data binding manually (for example where it isn't provided by the framework) using delegates and INotifyPropertyChanged fairly easily.
Data binding is typically used for a data view, generally a UI. Its purpose is to ensure that the data in the model matches what's being shown in the view, to put it in MVC/MVVM terms. No logic should happen in a data binder, although format conversions are acceptable (in WPF you can provide this as a binding argument, in WinForms you have to create a view model that's tightly bound to the view and put the conversion in there – obligatory self promotion).
Delegates are a general method to trigger code off another object's event. I'm assuming that in this context you're talking about handling change notifications on one object and updating another object as a result. This is quite similar to data binding, but the difference is that while data binding typically creates a 'vertical' binding (i.e. the view layer and model or view-model layer classes of the same concept), notifications between data objects is a 'horizontal' binding (i.e. classes in the same layer but relating to different concepts). You'd typically use delegates for this, with the handlers in a central controller class, because there is generally calculation or business logic required beyond simply assigning properties, as well as because data binding isn't typically available in such a scenario.
|
|
|
|
|
Thanks for confirming my comprehension.
Any opinions on performance?
|
|
|
|
|
I'd expect a delegate to be faster because data binding goes through reflection, but there won't be much difference. Neither should be a bottleneck in a real system.
|
|
|
|
|
Hi Everyone!
My problem might be very easy for you but I am having difficulty trying to solve this.
I have a menu strip on my form. Currently it occupies only half the size of my form. What I am trying to do is make the menu strip items occupy the entire form, and when the form re-sizes, it will also adjust its height and/or width.
I tried setting the auto size property of the menu strip but it does not solve the problem.
Do you have any ideas guys on how to solve this? I will appreciate any kind of solution.
Thanks folks!
|
|
|
|
|
That's how MenuStrip (in fact ToolStrip , from which it derives) works. You can manually override this behavior by handling the form's resize event and increasing/decreasing the Margin property of each top-level menu item.
/ravi
|
|
|
|
|
If this is Windows Forms, an instance of a MenuStrip Control dragged on to a Form at design-time should automatically dock to the top of the Form, and fit to the entire width of the Form: that's an outcome of its default Dock Property, which is DockStyle.Top. At run-time the MenuStrip will expand, or contract, so it's always the width of the Form.DisplayRectangle.Width.
So, I am not sure I understand your question: are you perhaps wishing to have whatever Controls or MenuItems in your MenuStrip somehow distributed across the current width of the Form ?
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
BillWoodruff wrote: Controls or MenuItems in your MenuStrip somehow distributed across the current width of the Form I think (i.e. I assumed) that's what the OP wants to do. Goes against the standard and what users expect, IMHO.
/ravi
|
|
|
|
|
Hmm, yeah your right BiillWoodruff, it occupies the entire width but the items does not expand to maximize the remaining spaces, what I wish/want is that menu strip items are distributed across the width of the form, leaving no empty spaces.
Sorry for the confusion. Do you have solution in mind?
|
|
|
|
|
I don't know of a solution or an an example. The reason is because you're going against all normal practices and what Microsoft has baked into Windows. The philosophy is that users must have a consistent experience acrossed all applications. Controls that look the same should all work the same so as to not confuse users.
In order to do what you want, I believe you would have to owner draw the entire menu, or come up with your own menu controls without using the standard toolbox ones.
|
|
|
|
|
Thanks Dave for the reply,
Of course, I don't want user of the application to get confused, it will just expand or shrink depending on user form size or user monitor size if maximized or the reverse. The menu item is still there, it will be always visible to user, it will not change the order, just the height or width.
yeah, I might going against what microsoft baked but I find it challenging and I believe we all like challenges right?
Thanks again. 
|
|
|
|
|
Did my solution not work?
/ravi
|
|
|
|
|
Thanks Ravi!
I haven't tried it out yet, I will let you know if it works.
Thanks for the idea!
Cheers! 
|
|
|
|
|
Hey Ravi, I tried your suggestion regarding setting the margin. Hmm, but I did not achieve what I want, it just put padding on the menu strip as a whole. I want to share you what I did. See code below.
private void ResizeMenu()
{
int itemHeight = (int) (Math.Floor((double)(this.Size.Height / (this.menuStrip1.Items.Count + 1))));
foreach (ToolStripMenuItem item in this.menuStrip1.Items)
{
int prevWidth = item.Size.Width;
item.Size = new Size(prevWidth, itemHeight);
}
}
Sorry I can't format nicely my code here. I am calling the method when form resizes.
Thanks for your help!
|
|
|
|
|
That's not what I meant. Change each item's Margin property instead (specifically the .Left member).
/ravi
|
|
|
|
|
hi,
I have a FTP location from where i want to get files, which are created on a date which is saved in the local machine.
Is it possible to do that,when i searched the data is retrieved as stream , where i cant give a filter condition. (with my knowledge)
Please suggest a solution.
Thanks
Sandeep
|
|
|
|
|
You may want to use NetFTP[^].
/ravi
|
|
|
|
|
http://www.codeproject.com/Questions/163452/how-to-get-the-latest-file-in-a-FTP-or-directory-u
got the solution 
|
|
|
|
|
How to access remote file directories without permission from remote system.
|
|
|
|
|
You want us to tell you how to get files that the ownere doesn't want you to have? No chance!
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
hi
how can move a rectangle over desktop area and taking picture.i want to be able to move the rectangle around pressing left mouse cursor and keep capturing pictures.
your help is greatly appreciated
abol
|
|
|
|
|
|