Jump to content

Recommended Posts

Posted

Hello,

I am creating a project where I need to have pre loaded html appear in a text box. Here is an example:

textbox1.text = "<HTML><CODE></HERE>" & Textbox2.text & "<More HTML HERE></Body>"

Is what I'm trying to accomplish here possible? No, I cant open an HTML file to the text box because I need reference to other text box controls. Any help is greatly appreciated. Thanks.

Micah C

Posted

Looks fine to me. If its not working properly or giving you errors insert a double of the problem character. That tells VB you want the actual character to be printed, rather than caring out an action on it.

In addition, you may want to create a new line like actual html code would appear like in say something like notepad, so it appears like this:

<html>

<head>

</head>

<body>

<p>Some Text to Display</p>

</body>

</html>

To do this, use a rich textbox control or enable an existing textbox control's multiline property. Append VB's vbNewLine command wherever you want a return to occur, like this:

TextBox1.Text = "<html>" & vbNewLine & "<head>" & vbNewLine & "</head>" & vbNewLine.... and so on.

  • 3 weeks later...
Posted

Micah C,

It is possible, You can load anything you like into the text property of a control at runtime, as it's just a normal string object.

The problem your going to have is:

A) If this is to be rendered on a web page, then forget it, as you'll either loose the formatting, or royally confuse the ASP.NET engine.

B ) If it's going in a winforms app, and your expecting the formatting to show up nicely, again forget it. The winform variants of these controls will just display the tags, as is without trying to interpret them.

There are components that can use HTML for formatting, and some of them are free, i would suggest starting your search at http://visualstudiogallery.com/ , however an easier way if you need to use HTML for formatting and embed items from other controls in, is probably to create a hidden form in your application.

Populate said form with your controls, and add some logic in to access them. Then in your main form use a web browser control stretched across the whole form with it's background color set to your forms background color.

You can then load your HTML strings in from your resources in the app, and use simple string replaces to swap tokens for control values, before squirting the HTML code into the web browser control.

Iv'e used similar methods myself on other projects and while not perfect they are reasonably effective, and you can do some pretty eye catching stuff.

You could also try ditching winforms and using windows presentation foundation and/or silverlight.

Cheers

Shawty

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...