C# - Design Pattern For Custom Events In .NET?

Feb 21, 2010

What is the proper design pattern for custom events in .NET (VB or C#).

I am refering to custom events, where in you override the AddHandler, RemoveHander, and RaiseEvent methods.

View 1 Replies


ADVERTISEMENT

Looking For Design Pattern / For Each Instead Of For With Index

Jun 4, 2012

Using VB.Net, I'm looking for best practices in dealing with the following idiom:[code]What I really want is something VB.Net doesn't offer -- additional and simultaneous iterators on For Each statements.[code]I'm interested in both Linq and non-Linq recommendations, comments about Copy method design, comparisions to C# or other languages.

View 3 Replies

.net - Design Pattern For TypeOf Subclass?

Mar 4, 2012

I am working on a parser for a serial data protocol. I have an overarching Packet class, a couple sub-classes such as CommandPacket and StatusPacket, and then a few sub-classes of each of those:

[Code]..

While I don't think it is entirely relelvant to the discussion, I am doing this in VB.NET. There is also a similar (but not quite the same) question posted here: Java - subclass validation design pattern

View 2 Replies

Design Pattern For Database Interaction?

Mar 12, 2012

I've been studying design patterns off-and-on now for a project I've recently been working on. I've been fortunate with this last one not to have to work with databases, but will soon have an opportunity.

View 8 Replies

'Producer Consumer' Design Pattern Using Queues?

Jul 23, 2009

I'm trying to replicate a design pattern used in a graphical programming language called LabVIEW. One thread produces commands, and another thread, or series of threads, consumes the commands.This is very similar to using Queues in VB...but there doesn't seem to be an easy way to start the consumer thread when new items are added to the queue.

Here is what I would like to accomplish, please let me know if there is a straightforward way to accomplish this with out of box .Net functionality.1) Start the Consumer Thread...it sits idle, waiting for some new commands to appear in its Queue.2) Producer places a few commands into the Queue. Example: "Home X Axis", "Home Y Axis", "Initialize Pump", "Display Ready Message"3) Consumer thread 'wakes up' at seeing the new commands, then performs the 4 tasks specified in 2.4) Consumer thread goes 'idle' again, and simply waits for new commands to appear in the Queue.

Process can continue on and on forever. The main problem I see with Queues is that there is no 'Wait for Something to Appear in Queue then Retrieve it" functionality. I don't want to use a perpetual loop to keep checking ever n milliseconds.

View 1 Replies

C# - Anonymous Method Alternative For Design Pattern?

Apr 18, 2012

With C# anonymous delegates, we can avoid declaration of extra method, I know in VB.NET they're not available, but is there a design pattern that I can use so that I can avoid writing an extra method each time? I need it for SPSecurity.RunWithElevatedPrivileges which will be used a lot of times in our code.

[Code]...

View 1 Replies

C# - Design Pattern For Dealing With Syncing Variables?

Jan 30, 2012

Suppose I have two events:

Public Sub Control1Updated() Handles control1.TextChanged
control2.Text = SomeFunction(control1.Text)
End Sub

[code]....

Basically the pairs of {control1.Text, control2.Text} and {control2.Text, control1.Text} should be the same. If control1.Text is changed to let's say "a" then control2.Text is ALWAYS "b". If control2.Text is changed to "b" then control1.Text is ALWAYS "a". How do I achieve this with events without going into an infinite loop? [the best I can think of is to make a check if the other control.Text is already the desired value].

View 1 Replies

What Are The Features Of The Controller Class In The MVC Design Pattern

Aug 13, 2009

In the MVC design pattern we must use a controller(s) classes.

What are the fucntions (features) of the controller apart from handling communication bewteen Model and View?e.eg; can we include input validation code in the controller?

View 4 Replies

What Type Of Code Should Put In The Controller In The MVC Design Pattern

Jul 7, 2009

In teh MVC design pattern, Controller is strongly related to the view (GUI). IN my application i need to generated a new BrandID, i used stored procedure to retreive the highest BrandID from teh DB (The model calls the stored procedure and sends the retreival value to the Controller), then in the controller increments the BrandID by "1" to create a new brand ID. SInce, controller is strogly related to "view", should i include this "brandID increment" part in teh controller or in the model classes?

View 3 Replies

C# - Which Design Pattern For Activity Logging (Audit Trailing)

Jun 15, 2012

I have a winform which allows people to edit data from a database, to simplify things assume there is a Customer table in database with 3 fields - Name, City, Country. Through winform(s) people can Add/Edit/Delete customers.For each of these actions we need to save:

What the field names are (Name,City,Country in this case)What the field values were before they were modified What the field values are after they are modified.If the action is Add or Delete then 2 and 3 will be the same.I have already implemented this using XMLSerialisation (but not using any of the design patterns) and my XML output looks like this.

<?xml version="1.0" encoding="utf-8"?>
<ActivityItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserID>26</UserID>
<FormTitle>frmCustomer</FormTitle>

[code]....

The solution can handle different areas of the system with different number of fields (i.e the same thing works when you are modifying Products for instance).is there a well defined design pattern to deal with this kind of behavior?

View 2 Replies

Lifetime Of Multiple Instances Of An Object / Design Pattern?

Sep 5, 2009

having difficulty with understanding object lifetime / instantiation.I have a windows from with a datagridview and a panel. The datagridview has a checkbox column and a list of names which is populated from a database.The panel has a few text boxes (e.g. name, age, favourite sports team) and a 'save changes' button.

The idea is that when the user selects a person in the datagridview by checking the appropriate checkbox then the panel shows the relevant data for that person (name, age, fav sports team) by pulling the data from a database. If the user would like to update the person's details they can do so by typing in the textboxes and then clicking the 'save changes' button. All quite simple so far.

The way I have designed this is to have a 'panel' class and to create an instance when the user checks a checkbox.(NB - the reason I have created a 'panel' class is that I intend to replicate the datagridview and panel on other tabpages within my form and thought it would be useful to have a generic 'panel' class that I could re-use.)

My code looks a bit like this:

If CheckBoxClicked Then
Dim UpdatePanel As New UpdatePanel(MyForm.NameTextBox, MyForm.AgeTextBox, MyForm.FavSportTeamTextBox, MyForm.SaveButton)
UpdatePanel.GetData()
...

When the user clicks the SaveButton the data is updated to the database and I have a display message (simple textbox) which says "Update successful" and displays for 5 seconds before hiding itself.

Here is the problem:Suppose a user checks a checkbox, reviews the data and does not make any changes, and then checks another checkbox and decides to update the data by clicking the 'save changes' button. What happens is that the "Update successful" message is displayed twice.

I think this is because every time the user checks a checkbox an instance of UpdatePanel is created. If a I select five different people using the checkboxes and then hit 'save changes' I get five "Update successful" messages.

I am not sure how to overcome this. It feels like each time a checkbox is clicked I need to check if an instance of UpdatePanel exists and then destroy it. I tried using UpdatePanel = Nothing and also investigated IDisposable and GC.Collect() but with no luck.

[code]....

View 1 Replies

Asp.net - Refactor To Design Pattern: Displaying/hiding Different Combinations Of Controls Based On State?

May 26, 2009

Assume you have controls A, B, C, D and E all with a Visibility property. You also have states 1,2,3,4,5 and 6 in which various combinations of your controls would be displayed. Currently this is being handled by switch statements for each state: i.e.

Select Case PageState
case "1"
a.visible = false
b.visible = true

[code]....

As you can imagine, this becomes a pain as every state needs a show/hide statement for each control. How can I refactor this so that adding controls and/or states becomes trivial?My first instinct is to extend the control and add a collection of states that it should display for but this sounds like overkill.

Edit:I was deliberately vague in my question in case this has other implications. In my current instance the "controls" in question are ASP Panels. Does that change anything?

View 4 Replies

C# - Get A Code Template/design Pattern Can Use When Reacting To Mouse Clicks Or Button Presses?

May 3, 2011

One of the problems that I constantly see with Winforms applications is that the GUI thread is stuck while a long-running task is running or just plain stops refreshing (yes, I know - needs threading). Is there a code template/design pattern I can use when reacting to mouse clicks or button presses? Should there be a processing thread always running in the GUI app? Basically, how do I write a great Winforms Application that is easy to maintain and doesn't have any quirky refresh bugs?

View 4 Replies

Handle Events For Objects NOT Created In The Design Tab?

Jan 10, 2012

I have created a PictureBox array to hold 104 playing cards that are all visible at the same time.I did this with this line in the declarations:Shared Card(104) As PictureBox

And with these lines in the Form_Load module:

For I% = 1 To 104
Card(I%) = New PictureBox
Card(I%).Name = String.Format("Card{0}", I%.ToString)
Card(I%).Size = New Size(71, 96)

[Code]...

I have been successful in creating the array, positioning each and entering the images for all 104 PictureBoxes, but now I want to add code for the event "MouseDown.I copied the code for this event from my VB3 program and VB10 automatically updated the list of parameters, but nothing has linked the objects (Card) to the code.

I have tried to append "Handles Card.MouseDown" as well as several variations with brackets to indicate that it is an array.Auto-complete doesn't include "Card" as an option, and of course, since the array was never an object added to the form design, I can't create the empty module from there.

View 7 Replies

Design A Custom GUI?

Jul 7, 2011

I'm just wondering how you'd go about designing something like this:

I know its made in Photoshop, but is there a program/addon that the transition into a GUI easier? Or is it all code?

View 34 Replies

Add A Design-time Attribute To A Custom Control?

Jul 29, 2009

setting the default value for an integer attribute of a custom control seems to have stopped working. The following code adds the Maximum attribute to the design-time properties table, but the default value pops up as 0, not 99:

<System.ComponentModel.Browsable(True)> _
<System.ComponentModel.Category("Behavior")> _
<System.ComponentModel.Description("highest value possible")> _

[Code].....

View 4 Replies

Design-Time Support For Custom Controls?

Apr 17, 2011

Now as the title says, I'm looking for guidance on some design-time support for the many custom controls I'm working on at the moment.At the moment I'm 3 months in on a Business and Inventory management system for my mothers business. It contains many, many custom controls I had to build from scratch because the ones provided just didn't cut it for what I needed. Now one in particular is a tab page control. Just as the provided TabControl Visual Studios supply's us. It has a lot of design time control. Such as clicking the tabs and adding controls to the panels being brought to front by the corresponding tab being clicked. I had a friend of mine try to show me what I had to do, but the way I had already built my control would have made it difficult - His words, so he never officially showed me anything. If it is true what he said then I can skip that, no problem. But adding the controls to the panels during design time I must have, but cannot seem to find anything through Google searches, text books or even kids majoring in software engineering.

View 4 Replies

Option For User To Design Custom Reports

Dec 10, 2011

How can I give option to user to design there own reports? i.e. They should be able to define
1. Report Title
2. Reports Fields(When they click on Work Order button they should be able to view Work Order Table column and they should be able to select columns then a report should be composed. Then all the Column should be in the form datagrid. Is it possible.

View 10 Replies

VS 2008 Custom Treenode At Design Time

Dec 22, 2010

I'm currently working on a treeview but want to add custom nodes at design time, is this possible?Also the treeview is part of a control, so i have created a control designer and added a custom design time form to add my custom nodes, but can't seem to get the nodes into the treeview in design time, and serialize into the form automatically?All my custom tree node is is an extra integer at the minute, but more properties will be added later if I can get this working.

View 6 Replies

Create Custom Events In .net?

Nov 21, 2011

I have created a control in vb.net. Now I want that control to send some message(fire an event called recieve) and the parent application that implements it will have to create an even listener called recieve and do actions accordingly.

View 3 Replies

How To Create Custom Events

Feb 11, 2011

Is it possible to create my own event in vb.net .

I need an event for WindowState = Normal.

View 1 Replies

.net - How To Show A Form's Custom Property At Design Time

Oct 22, 2010

I have a form where I have created a custom property, DataEntryRole, and set its Browsable attribute to True, as shown:

<Browsable(True)> _
Public Property DataEntryRole() As UserRole.PossibleRoles
Get
Return mDataEntryRole
End Get

[Code]...

When I view the designer for my form, DataEntryRole doesn't appear in the property box. I assume that it should appear if I were to create another form that inherited from this base form, but that's not what I want. I want this property to show up in my current form.

View 2 Replies

VS2008: Nested Custom Components In Design Time?

Sep 4, 2009

I have a custom component, that contains a list of another components.If I add a child component to the list, it shows up on the same level as the parent component in the document outline window.How can I make it a subitem of the parent component? (similarly to e.g. TabPages that are subitems of a TabControl)

Here is my code:
Public Class SomeComponent
Inherits Component

[code].....

View 1 Replies

Asp.net - Add Buttons With Events To A Custom TreeNode?

Dec 22, 2009

I extended treeview, treenode, and nodetype so I could have custom nodes. Certain nodes have image buttons on them allowing them to add a child node or delete the node. I can't handle any of the events from my buttons.Public Class ContentTreeView Inherits TreeView Public Event OnAddChild(ByVal sender As Object, ByVal e As EventArgs) Public Event OnDelete(ByVal sender As Object, ByVal e As EventArgs)

[Code]...

View 2 Replies

Creating Custom Events In Project?

Sep 28, 2009

I am working on a project that has some events already created and working. One of these events is called SelectedIndexChanged Event. I am using it for one of my Subs in my frmNewInspection Class, and I am trying to use it for a second Sub and it says that "Event SelectedIndexChanged Cannot Be Found".

The event is created here in a class called LabelComoBox
Private Sub tctlInspection_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tctlInspection.SelectedIndexChanged
'MsgBox("Index: " & tctlInspection.SelectedIndex.ToString)
[Code] .....

View 11 Replies

Good Time To Use Custom Events?

Nov 3, 2009

How to implement my own events I'm not sure why do I use them. I mean instead of rising event you could simply call functions right? This is as close as I got to a good reason:
1) If you call a function that does one thing and then based on result it needs to do something else it may be a good idea to do that something else in event function that is raised when that first thing was done. This way you avoid creating long functions and can make system more intuitive.
2) If object1 is inside object2 (a variable) and object2 has function DoThis and in that function affect something in object2's parent class it's better to use event in object1 rather than mess with parent (object1) inside object2.

View 6 Replies

IDE :: Create Custom Toolbar Events?

Jul 22, 2009

i just creates a new custom filters toolbar and compile into a dll to be used on my projects but now i face a problem
the controls inside my toolbar used t create a filter (combos and text boxes) has the event for when text change but this event does not pass through my dll to be used on my projetc so i have no way of knowing when the user change a value on the filter, how can i pass this event?

View 3 Replies

Implementing A Custom Control With A Typed Collection For Use At Design Time

Oct 14, 2010

I am having a problem with the Visual Basic property collection editor .

I have created a Custom Type

Public Class Field
Private Item As Integer
Private Name As String = "FieldName"

[ode]....

View 1 Replies

VS 2008 - Custom Control Not Showing On Form In Design Mode

Jan 31, 2011

I have created a custom Combobox and added it to my toolbox, and it works well. Now I have added a custom ListBox to the same file as the combo box, but it does not show on my designer when I place it. I can however add it at runtime.
''ComboBox
<DefaultEvent("SelectedIndexChanged"), _
ToolboxBitmap(GetType(System.Windows.Forms.ComboBox))> _
Public Class ProjectsComboBox
Inherits ComboBox
''My Customization
[Code] .....
I have tried removing the "DefaultEvent..." and still no dice.

View 2 Replies

Catching Mouse Events For A Custom SplitContainerDesigner

Jul 16, 2010

I'm trying to create a user control that will provide a draggable splitter between two panels — exactly like SplitContainer — in a custom IDesignerHost implementation. SplitContainer itself, as far as I can tell, is not an option; it will raise an exception unless used in Visual Studio's Designer.

My implementation would look roughly like this, except that I'm not receiving the necessary mouse events. I've tried event handlers, On* overrides and overriding WndProc in the user control itself, the host control, and the parent form, but I don't appear to receive WM_MOUSEMOVE, WM_LBUTTONDOWN or WM_LBUTTONUP events anywhere. Per this bug report, I should be receiving WM_MOUSEMOVE in "the control designer"; I'm not sure what that refers to in this case.

how I can implement a draggable splitter?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved