Log in to see Cloud of Tags

Wealth-Lab Wiki

Copy to Clipboard

RSS

Syntax


public static void CopyText(this WealthScript obj, string text)
public static void CopyObject(this WealthScript obj, object ob)

public static void CopyText(string text) public static void CopyObject(object ob)

Parameter Description

textA string to be copied to clipboard
objValue of type object to be copied to clipboard

Description

Although .NET has support for copying to clipboard, making it from Wealth-Lab would be pretty tricky. For your convenience, CopyText is a simple static method for copying a text string to Windows clipboard. Its companion method CopyObject was designed to copy any data (not just text) as type object.

Examples

Example below copies to clipboard a block of text containing a header and series of OHLC values and the 20-bar SMA value at each bar, separated with tabs.

Example using C# extension methods:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class ClipboardDemo : WealthScript { protected override void Execute() { SMA sma = SMA.Series( Close,20 ); char sep = '\t'; string s = "Date" + sep + "Open" + sep + "High" + sep + "Low" + sep + "SMA[bar] \n"; for(int i = sma.FirstValidValue; i < Bars.Count; i++) { s += ( Date[i].ToShortDateString() + sep + Open[i] + sep + High[i] + sep + Low[i] + sep + Close[i] + sep + Bars.FormatValue( sma[i] ) + "\n" ); } this.CopyText( s ); } } }

Advanced example

Copying formatted text and chart image to clipboard and creating a new RTF document (open in Wordpad or Word):


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using System.Windows.Forms;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { private void PasteBitmap(RichTextBox richTextBox, Bitmap myBitmap) { // Copy the bitmap to the clipboard. this.CopyObject(myBitmap);

DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);

if(richTextBox.CanPaste(myFormat)) richTextBox.Paste(myFormat); } protected override void Execute() { const string newLine = "\n"; // We're using a RichTextBox control to save some formatted text and an image as RTF RichTextBox richTextBox1 = new RichTextBox(); // Location of your output RTF document string location = @"c:\Temp\test.rtf";

// Define new font style Font font = new Font("Times New Roman", 14, FontStyle.Bold); richTextBox1.SelectionFont = font; richTextBox1.SelectionColor = Color.Red; // A text sentence richTextBox1.AppendText("Let me share a chart with you..." + newLine); // Take a screenshot Bitmap bm = GetChartBitmap( 300, 200 );

// Paste the screenshot as bitmap PasteBitmap( richTextBox1, bm ); // Define yet another font style Font font2 = new Font("Arial", 12, FontStyle.Bold); richTextBox1.SelectionFont = font2; richTextBox1.SelectionColor = Color.Blue; // A text sentence richTextBox1.AppendText(newLine + "This was my Wealth-Lab chart!"); richTextBox1.SaveFile(location, RichTextBoxStreamType.RichText);

} } }

Legacy syntax example:

Note: since the function is marked as static, you don't have to create an instance of the MyClipboard class that contains it:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class ClipboardDemo : WealthScript { protected override void Execute() { SMA sma = SMA.Series( Close,20 ); char sep = '\t'; string s = "Date" + sep + "Open" + sep + "High" + sep + "Low" + sep + "SMA[bar] \n"; for(int i = sma.FirstValidValue; i < Bars.Count; i++) { s += ( Date[i].ToShortDateString() + sep + Open[i] + sep + High[i] + sep + Low[i] + sep + Close[i] + sep + Bars.FormatValue( sma[i] ) + "\n" ); } MyClipboard.CopyText( s ); } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.