Click here to Skip to main content
15,890,185 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Question[Message Deleted] Pin
JUNEYT10-Feb-09 6:15
JUNEYT10-Feb-09 6:15 
GeneralRe: Why do I get "System.ArgumentOutOfRangeException" for recently added columns to listview? Pin
Luc Pattyn10-Feb-09 6:27
sitebuilderLuc Pattyn10-Feb-09 6:27 
AnswerRe: Why do I get "System.ArgumentOutOfRangeException" for recently added columns to listview? Pin
Dave Kreskowiak10-Feb-09 6:36
mveDave Kreskowiak10-Feb-09 6:36 
RantRe: [Message Deleted] Pin
Smithers-Jones10-Feb-09 7:21
Smithers-Jones10-Feb-09 7:21 
Questionimages/photos/pictures Pin
ngugi10-Feb-09 5:42
ngugi10-Feb-09 5:42 
AnswerRe: images/photos/pictures Pin
Henry Minute10-Feb-09 6:19
Henry Minute10-Feb-09 6:19 
AnswerRe: images/photos/pictures Pin
Dave Kreskowiak10-Feb-09 6:34
mveDave Kreskowiak10-Feb-09 6:34 
QuestionAdding a control from within a class Pin
Paul Hasler10-Feb-09 4:16
Paul Hasler10-Feb-09 4:16 
This is a bit of a Newbie question... Blush | :O

I am trying to write a class which adds a control to it's host, where the host could be any suitable container such as a Panel, GroupBox, or a Form.

I know I can add a control directly to a Form for example in the following way:

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Load
       Dim myControl As New SomeControl

       With myControl
           .Left = myLeft
           .Top = myTop
           .Width = myWidth
           .Height = myHeight
           .Visible = True
       End With

       Me.Controls.Add(myControl)

   End Sub


But I'm having trouble doing it from within a class.

   Public Class MyNewClass
    .
    .
    .
    Public Sub New(ByVal newLeft As Short, ByVal newRight As Short, ByVal newWidth As Short,_
ByVal newHeight As Short)
       myLeft = newLeft
       myRight = newRight
       myWidth = newWidth
       myHeight = newHeight

       Dim myControl As New SomeControl

       With myControl
           .Left = myLeft
           .Top = myTop
           .Width = myWidth
           .Height = myHeight
           .Visible = True
       End With

       Me.Controls.Add(myControl)

    End Sub


Clearly "Me" now refers to the instance of MyNewClass and not the Container or Form in which it is intended to go, so it's not going to work. Frown | :(

How should I do it?

Thanks in advance.
AnswerRe: Adding a control from within a class Pin
JoeSharp10-Feb-09 4:30
JoeSharp10-Feb-09 4:30 
GeneralRe: Adding a control from within a class Pin
Jon_Boy10-Feb-09 5:31
Jon_Boy10-Feb-09 5:31 
AnswerRe: Adding a control from within a class Pin
Dave Kreskowiak10-Feb-09 6:33
mveDave Kreskowiak10-Feb-09 6:33 
AnswerRe: Adding a control from within a class Pin
Paul Hasler10-Feb-09 11:47
Paul Hasler10-Feb-09 11:47 
QuestionTwo questions regarding custom user controls and the toolbox. Pin
Jon_Boy10-Feb-09 3:39
Jon_Boy10-Feb-09 3:39 
AnswerRe: Two questions regarding custom user controls and the toolbox. Pin
Dave Kreskowiak10-Feb-09 4:05
mveDave Kreskowiak10-Feb-09 4:05 
GeneralRe: Two questions regarding custom user controls and the toolbox. Pin
Jon_Boy10-Feb-09 4:17
Jon_Boy10-Feb-09 4:17 
Questionfingerprint image quality estimation Pin
kebedetesema10-Feb-09 3:17
kebedetesema10-Feb-09 3:17 
AnswerRe: fingerprint image quality estimation Pin
Dave Kreskowiak10-Feb-09 3:57
mveDave Kreskowiak10-Feb-09 3:57 
QuestionTextbox value to Textbox in webpage Pin
vijay248210-Feb-09 2:12
vijay248210-Feb-09 2:12 
AnswerRe: Textbox value to Textbox in webpage Pin
vaghelabhavesh10-Feb-09 3:37
vaghelabhavesh10-Feb-09 3:37 
AnswerRe: Textbox value to Textbox in webpage Pin
shawndeprey10-Feb-09 14:53
shawndeprey10-Feb-09 14:53 
GeneralRe: Textbox value to Textbox in webpage Pin
vijay248211-Feb-09 3:28
vijay248211-Feb-09 3:28 
Generalneeds to write a program with MATLAB using Simulated annealing technique Pin
awoyale10-Feb-09 2:04
awoyale10-Feb-09 2:04 
AnswerRe: needs to write a program with MATLAB using Simulated annealing technique Pin
Maxwell Barrett10-Feb-09 2:32
Maxwell Barrett10-Feb-09 2:32 
GeneralRe: needs to write a program with MATLAB using Simulated annealing technique Pin
Dave Kreskowiak10-Feb-09 3:54
mveDave Kreskowiak10-Feb-09 3:54 
QuestionTiming variations to get network answer during sending sms Pin
scothyhut10-Feb-09 1:04
scothyhut10-Feb-09 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.