无法绕过STAThreadAttribute [英] Can't get around STAThreadAttribute

查看:69
本文介绍了无法绕过STAThreadAttribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的.apsx页面中出现以下代码时:


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System .EventArgs)处理Button1.Click


Dim test As New MyTestClass


''创建ClipBoard对象的实例

Dim sHyperLink As String


Dim data_object As New System.Windows.Forms.DataObject

Dim DataFormats As System.Windows.Forms.DataFormats

Dim objClipboard As System.Windows.Forms.Clipboard


sHyperLink = test.CreateHyperlink(CInt(TextBox1.Text),TextBox2.Text)


''将HyperLink写入剪贴板

data_object.SetData(DataFormats.Html,True,sHyperLink)

objClipboard.SetDataObject(data_object,True)

结束子


我收到此错误:


当前线程必须设置为Single Thread Apartment(STA在OLE之前的模式

可以进行调用。确保您的主要功能上标有STAThreadAttribute




因为我正在尝试将项目放在客户端剪贴板上,有没有办法<在System.Windows.Forms命名空间周围的
仍然可以使用我需要的这些

类?如果没有,我如何解决STAThreadAttribute错误?

When the following code is excuted from my .apsx page:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim test As New MyTestClass

''Create an Instance of the ClipBoard Object
Dim sHyperLink As String

Dim data_object As New System.Windows.Forms.DataObject
Dim DataFormats As System.Windows.Forms.DataFormats
Dim objClipboard As System.Windows.Forms.Clipboard

sHyperLink = test.CreateHyperlink(CInt(TextBox1.Text), TextBox2.Text)

''Write HyperLink to Clip Board
data_object.SetData(DataFormats.Html, True, sHyperLink)
objClipboard.SetDataObject(data_object, True)
End Sub

I get this error:

The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.

Since I''m trying to place items on the Clients Clipboard, is there a way
around the System.Windows.Forms Namespace and still be able to use these
classes I need? If not, how do I get around the STAThreadAttribute error?

推荐答案

为什么不使用javascript?

http://dotnet.org.za/ eduard / archive / ... 7/29 / 3064.aspx


HTH,

Darren Kopp
http://blog.secudocs.com/

Why don''t you use javascript?

http://dotnet.org.za/eduard/archive/...7/29/3064.aspx

HTH,
Darren Kopp
http://blog.secudocs.com/


我想这并没有设置数据对象。但是,我不认为b $ b认为这适用于通过网站连接的人。

I guess that doesn''t set the data object though. However, I don''t
think that will work for people connecting over a website.


我有这个JavaScript功能并且它有效,但它没有设置我正在寻找的

格式:


///将源复制到剪贴板

函数copytoClipBoard(rSource)

{

if(rSource!="")

window.clipboardData.setData( 文字,rSource);

}


当我将超链接复制到剪贴板时,我希望它保留它的HTML

格式化。基本上,我正试图捕捉这样的东西

http:// www.somewhere.com 作为MyLink

我想只显示MyLink(蓝色带下划线和

代码隐藏是url作为超链接)。当我在Microsoft

Word文档中执行Ctrl + P时,它应该只使用蓝色下划线粘贴MyLink。


System.Windows.Forms.DataObject应该允许我这样做,但我不知道

如何让它与.aspx一起工作,因为它似乎只适用于Windows

表格。


" Darren Kopp"写道:
I have this JavaScript function and it works, but it doesn''t set the
formatting that I am looking for:

/// Copy Source to Clipboard
function copytoClipBoard(rSource)
{
if(rSource!= "")
window.clipboardData.setData("Text",rSource);
}

When I copy the hyperlink to the Clipboard I want it to retain it''s HTML
formatting. Basically, I''m trying to capture something like this

http://www.somewhere.com as MyLink

where I want only MyLink to show up (in blue with a underline and the
codebehind is the url as the hyperlink). When I do a Ctrl+P in a Microsoft
Word Document it should just paste MyLink with a blue underline ONLY.

System.Windows.Forms.DataObject should allow me to do that, but I don''t know
how to get it to work with .aspx, since it appears to only work with Windows
Forms.

"Darren Kopp" wrote:
为什么你不使用javascript?

http://dotnet.org.za/eduard/archive/...7/29/3064.aspx

HTH,
Darren Kopp
http:// blog.secudocs.com/
Why don''t you use javascript?

http://dotnet.org.za/eduard/archive/...7/29/3064.aspx

HTH,
Darren Kopp
http://blog.secudocs.com/



这篇关于无法绕过STAThreadAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆