Jump to content
Xtreme .Net Talk

Jarod

Avatar/Signature
  • Posts

    82
  • Joined

  • Last visited

About Jarod

  • Birthday 12/16/1979

Personal Information

  • Visual Studio .NET Version
    Visual Studio .NET Professional
  • .NET Preferred Language
    VB.NET

Jarod's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I already have that ! A & B inherits from BaseClass that inherits from Control. I agree with you, I can define that method in BaseClass and override it as needed in A & B. BUT :) doing that resolve only part of my problem. If I do that, I still have to test the type before calling it (remind that I loop on the controls of the forms) For Each myControl In Me.GroupBox1.Controls if typeof myControl is BaseClass then Tools.myFunction(myControl) Next and I don't really like that !
  2. Here is my problem ! I have created some custom controls, let's say : Class A Inherits Control End Class Class B Inherits Control End Class Then I have a form with several controls and some custom controls. For my custom controls, I want to call a specific function. I wannot easily do a call for each of my control (too many controls) so I do a simple loop: With Tools classe defined as : Class Tools Public Sub myFunction(ByVal myObj As baseClass) If TypeOf myObj Is baseClass Then 'Do something ElseIf TypeOf myObj Is A Then 'Do something else ElseIf TypeOf myObj Is B Then 'Do something else End If End Sub End Class It's highly dirty ! I don't want to do any cast, or use typeof... One better solution is to define my method in the baseClass, A & B class, and so use inheritance. But this would force me to test the type in my loop as I cannot add my method in the base class (Control class). That's why I would prefer a "Visitor class". So I want to modify my Tool class as : Class Tools Public Overloads Shared Sub FunctionCall(ByVal myObj As Control) 'Do Nothing Console.WriteLine("Call of FunctionCall(ByVal myObj As Control)") End Sub Public Overloads Shared Sub FunctionCall(ByVal myObj As baseClass) 'Do Something Console.WriteLine("Call of FunctionCall(ByVal myObj As baseClass)") End Sub Public Overloads Shared Sub FunctionCall(ByVal myObj As A) 'Do Something Console.WriteLine("Call of FunctionCall(ByVal myObj As A)") End Sub Public Overloads Shared Sub FunctionCall(ByVal myObj As B) 'Do Something Console.WriteLine("Call of FunctionCall(ByVal myObj As B)") End Sub End Class and do my loop simply like For Each myControl In Me.GroupBox1.Controls Tools.myFunction(myControl) Next But this doesn't work ! Even all the controls in my groupbox are of type A, they are stored in a member of static type Control. And the static type is use at compilation time to determine which method is call and so Public Overloads Shared Sub FunctionCall(ByVal myObj As Control) is called. Can we determine that a method must be called using the Dynamic type of the object and not the static type ? (so the "A version" will be called instead of the "Control Version") Do you see an another solution ? Thanks,
  3. No sorry... I just kept my System.Windows.Forms.Timer for now... I haven't found any solution and couldn't reproduce that problem in a simple sample.
  4. btw, we don't really see on the latest attachement. The buttons are tranparent. here is a new screenshot done on my IDE, we can see the solutionExplorer beside :-) transparentbuttons2.zip
  5. well... here is a bitmap to show the result. No buttons : after the load, as the forms is shown With buttons : after a refresh (here I have minimized the form and restored it) For the code, I just do somthing like that : Private Sub myBase_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load DisplayLabels() end sub Private Sub DisplayLabels() 'Get the XML string containing the labels Dim myLabelString As String = GetLabelsForContext("WIZARD")) 'labelExplorer is a Wrapper for navigating more easily in the XML, 'getting a PathNavigator, and exposing properties to get attribute from the XML Dim myLabelExplorer As New LabelExplorer(myLabelString) With myLabelExplorer While .MoveNext Select Case .TXT_CODE Case "txt0698" : DisplayLabel(btnCancel, .VALUE, .TOOLTIP, .HELP) Case "txt0699" : DisplayLabel(btnFinish, .VALUE, .TOOLTIP, .HELP) 'Do the same for other controls End Select End While End With End Sub Public Sub DisplayLabel(ByVal myControl As Control, ByVal value As String, _ ByVal tooltip As String, ByVal help As String) If Not myControl Is Nothing Then myControl.Text = value If Not tooltip Is Nothing Then ToolTip1.SetToolTip(myControl, tooltip) End If If Not help Is Nothing Then HelpProvider1.SetHelpString(myControl, help) End If End If End Sub Btw, I use that kind of code for some other forms without any problem. transparentbuttons.zip
  6. I have a simple Windows Form with several TextBoxes and Two buttons. In the Load event, I change dynamically the text of the buttons and the caption text (depending of the user language) To do that, I get an XML file and I retreieve the correct values. For an unknown reason, my buttons are not painted (totally transparent) until I move to the next field. I use the exactly the same technique for several different forms that are painted correctly. No SuspendLayout or stuff like that... So at the end of the form, I do a myButton1.Refresh and it is ok but it is really wierd. Does someone has seen that ? Any idea ?
  7. Umm... because I was searching for a property called ReadOnly and that I missed this one..... :"> Ok thanks, this one does the job. :-D By the way, I'd still like to understand my VB problem...
  8. Here is my problem Now, to have a "read only checkbox", we have to disable it. I wanted to create my own Checkbox with a new property ReadOnly. I have done it like that : Imports System.ComponentModel Imports System.Windows.Forms '<summary> 'This class will implement a CheckBox with a ReadOnly property. THis will allow to have "white checkboxes" 'that can't be modified '</summary> <Drawing.ToolboxBitmap(GetType(CheckBox))> _ Public Class ReadOnlyCheckBox Inherits CheckBox Private m_ReadOnly As Boolean = False '<summary>Will be raised when the ReadOnly property is modified</summary> Public Event ReadOnlyChanged As EventHandler '--------------------------------------- '<summary>Will get or set the ReadOnly property</summary> '<value>True if the CheckBox is ReadOnly</value> <Description("Will get or set the ReadOnly property"), DefaultValue(False), Category("Behavior")> _ Public Property [ReadOnly]() As Boolean Get Return m_ReadOnly End Get Set(ByVal Value As Boolean) If Value <> m_ReadOnly Then m_ReadOnly = Value OnReadOnlyChanged(EventArgs.Empty) End If End Set End Property '--------------------------------------- '<summary>Will raise the <see cref="ReadOnlyChanged">ReadOnlyChanged</see> event</summary> '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param> Protected Overridable Sub OnReadOnlyChanged(ByVal e As EventArgs) RaiseEvent ReadOnlyChanged(Me, EventArgs.Empty) End Sub '--------------------------------------- '<summary>Override the OnMouseDown to allow the ReadOnly behaviour</summary> '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param> Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs) If Not m_ReadOnly Then MyBase.OnMouseDown(e) End Sub '--------------------------------------- '<summary>Override the OnMouseUp to allow the ReadOnly behaviour</summary> '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param> Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs) If Not m_ReadOnly Then MyBase.OnMouseUp(e) End Sub '--------------------------------------- '<summary>Override the OnKeyDown to allow the ReadOnly behaviour</summary> '<param name="e">A <see cref="KeyEventArgs">KeyEventArgs</see> that contains data of the event</param> Protected Overloads Overrides Sub OnKeyDown(ByVal e As KeyEventArgs) If Not m_ReadOnly Then MyBase.OnKeyDown(e) End Sub '--------------------------------------- '<summary>Override the OnKeyUp to allow the ReadOnly behaviour</summary> '<param name="e">A <see cref="KeyEventArgs">KeyEventArgs</see> that contains data of the event</param> Protected Overloads Overrides Sub OnKeyUp(ByVal e As KeyEventArgs) If Not m_ReadOnly Then MyBase.OnKeyUp(e) End Sub End Class As you can see, the code is very simple. I have created my control in a separate DLL. To test it, I have created a new project with a simple form. Set a normal TextBox and my new "ReadOnlyCheckBox". I run the project and it is ok. Note that for the test, the form windows must be visible at design time. I decide to test my property and set ReadOnlyChecBox1.ReadOnly = true on the designer. I compile, everything is ok. I run the project and I have the following error : "An error occurred while loading the document. Fix the error, and then try loading the document again. The error message follows : The designer cannot be modified at this time." And indeed VS.NET (2002) has tried to modify the designer. Why ? What's happening ? How can I solve that ? I have attached my simple test project if anyone have an idea... Also notice that I have tried to do exactly the same in C# and it seems to work properly... rocheckboxtesting.zip
  9. Hello, I have a form in which I have to do some treatment every X seconds. So first, I have created a wrapper of System.Windows.Forms.Timer class to execute some code every X seconds. It is working fine. The only disadventage of that solution is that the timer and the main form run in the same thread. As the treatment has begun quite time consuming, I have decided to let it work in a separate thread. So I had : 1. Transformed my wrapper to be a wrapper of System.Timers.Timer class (which will run in a separate thread) 2. Synchronized some critical method 3. Synchronized some data by using the ReaderLock and WriterLock 4. Modified the UI functions called by the separate thread like that : public sub MyThreadSafeUIMethod() If Me.InvokeRequired Me.Invoke(new MethodInvoker(addressof me.MyThreadSafeUIMethod)) else ' -- Do my stuff on UI end if end sub And for a reason I do not uderstand at all, my code doesn't work. There is no exception, it is "just" blocked on the Invoke call, as it didn't find the main UI thread. I have tried to reproduce that case on a small exemple but of course, it works perfectly. I have no idea why the call to Invoke can fail. The main thread is surely not stopped or suspended (the "thread debug windows" indicates it as running) Any idea of what can happen ?
  10. Yeah you are right. THt'as surely the best way, and then dealing with double buffering. But I was very lazy and didn't want to manage the 3Dlike style, the push effect and so on... Ok that's an opportunity to play with GDI+ But just to know, there is not a way to avoid the flickering if we have a lot of controls ?
  11. I have a panel with, say 100 buttons on it (MineSweeper-like game) In some cases (a mine has burst out) I want to hide all the buttons. So I simply do a loop avoer the controls and set Visible = False. To avoid flickering, I alo set SuspendLayout before the loop, and reset ResumeLayout after But there is still an awful flickering effect. Why ? How can I avoid that ?
  12. Ohhh... I have tried with ', /, \ but I hadn't thought to that Great Idea ! Thanks !
  13. Say you have a button's text set to "A&B" Even if the UseMnemoni is only set to labels, the displayed text will be "AB" and the B will be ued as a shortcut key. How can I be able to display "A & B" for a button text ?
  14. I have created a project and its corresponding setup. My problem is that my application is generating some files (user preferences for instance). And when I uninstall the application, those files remains (as they are not part of the setup) How can I create a setup project that will remove everything from my folder ?
  15. You are right... I haven't seen that my button had the DialogResult property set to "Cancel" (and that's what was closing my form) My mistake....
×
×
  • Create New...