ajm113


Error 6 'System.Windows.Forms.RichTextBox' does not contain a definition for 'FindControl'

Code Block

RichTextBox t = (RichTextBox)Form.FindControl("newRtb");


Isn't that is how it should be set up

Here is a list of names I am using for my application that works with the function.

Window = Form Of The App
newRtb = The RichTextBox - A am creating multiable textboxes for my tabs that allowes the user to create them.

I did ask my teacher about this, but I don't think he knew what I was talking about. If he did I would have to wait a while and I want to get my project done atleast before November. -Birthday Month-

The reason I say that is becuase I can only go to his clase every Tue and Thur which can take a while to get a project done in class.



Re: Visual C# General I need help configuring DirectCast in C#.

Peter Ritchie

The cast is being applied before the call to FindControl, so it's trying to call RichTextBox.FindControl, which doesn't exist.

Try

Code Block

RichTextBox t = (RichTextBox)(Form.FindControl("newRtb"));






Re: Visual C# General I need help configuring DirectCast in C#.

ajm113

Insignificantly it didn't work. It shows the same error...





Re: Visual C# General I need help configuring DirectCast in C#.

Peter Ritchie

Control.FindControl is an ASP.NET method, is this occurring in an ASP.NET application or a WinForms application

If it's a WinForms application, you can't use FindControl; what is it you're trying to accomplish






Re: Visual C# General I need help configuring DirectCast in C#.

ajm113

I am trying to create a scripting editor for a game and I created tabs that have RTBs in them and allow the user to create their own tabs with RTBs in them to create a script for their mod/map. The rtbs all have the same name. I am trying to have it so the user may paste or do what ever in a selected tab/rtb with the tools I supplied for the user.

How can I accomplish this if all of the stuff just goes to the tab I made my self in C# that lets the user get started off then a tab a user created and has selected.

Do you have any ideas for me to accomplish this Its been bothering me, and I searched all over the internet for this answer!





Re: Visual C# General I need help configuring DirectCast in C#.

Peter Ritchie

You can use the IndexOfKey method on the Controls collection of the Form to find controls by name. For example:

Code Block

int index = this.Controls.IndexOfKey("newRTB");

if (index != -1)

{

Control control = this.Controls[index];

// TODO: do something with control

}

This doesn't search controls of child controls, so if your users are adding a panel to a tab control you'll have to search the controls of the tab control, not the form.






Re: Visual C# General I need help configuring DirectCast in C#.

ajm113

I tried it like so:

Code Block

private void paste(object sender, System.EventArgs e)
{

int index = this.Controls.IndexOfKey("newRtb");

if (index != -1)
{

Control control = this.Controls[index];

control.Paste();

}


But I get this error.

Error 6 'System.Windows.Forms.Control' does not contain a definition for 'Paste'


Sorry, I am still learning more of C#. I used to be a wxPython programmer. Thats why I swicthed to C#, becuase I don't have to worry about the syntac.





Re: Visual C# General I need help configuring DirectCast in C#.

Peter Ritchie

That's a different error, with a different method. As a Control, it doesn't have a Paste method, you'll have to cast to a RichTextBox object, for example:

Code Block

private void paste(object sender, System.EventArgs e)

{

int index = this.Controls.IndexOfKey("newRtb");

if (index != -1)

{

Control control = this.Controls[index];

RichTextBox richTextBox = control as RichTextBox;

if (richTextBox != null)

{

richTextBox.Paste();

}

}

}






Re: Visual C# General I need help configuring DirectCast in C#.

ajm113

I get no errors, but it seems that the code does not do anything that I tell it to when I do a paste.





Re: Visual C# General I need help configuring DirectCast in C#.

Peter Ritchie

Did you copy something to the clipboard before you call the Paste method






Re: Visual C# General I need help configuring DirectCast in C#.

ajm113

Yeah I even tried the cut and copy function and they both don't do anything to the text.