Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it possible to use clipboard to hold some my own defined data?

 

eg:

Structure stData
  Dim a as Integer
  Dim b as String
End Structure
Dim ToHold(10) as stData

'procedure code
Clipboard.SetDataObject(ToHold(2))

'other procedure code
ToHold(3) = Clipboard.GetDataObject()

 

there is some expection with 'invalid cast', I've tried with CType and DirectCast but I can't handle it... please help me !!!

  • *Experts*
Posted

You need your Structure to be serializable: change the declaration

to this:

<Serializable()> _
Structure stData
  Dim a As Integer
  Dim b As String
End Structure

Also, you need to use the GetData method of the IDataObject

returned by that GetDataObject method.

Dim cbData As DataObject = Clipboard.GetDataObject()

If cbdata.GetDataPresent(GetType(stData).ToString) Then _
           ToHold(3) = cbdata.GetData(GetType(stData).ToString, True)

  • *Experts*
Posted

nevermind... Volte got it right. Me, not so much :)

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I still can't handle this.... would You mind if I paste some code:

Class Form2
   Public Enum typeTypObiektu
       PoleTekstowe = 0
       PoleWyboru = 1
       PoleOpcji = 2
   End Enum
   Public Structure typePodobiektyObiektu
       Dim Top As Integer
       Dim Left As Integer
   End Structure
   <Serializable()> _
   Public Structure typeObiektStrony
       Dim Nazwa As String
       Dim Rodzaj As typeTypObiektu
       Dim Text As String
       Dim Kolor As Color
       Dim Czcionka As Font
       Dim Wyrównanie As StringAlignment
       Dim PodObiekty() As typePodobiektyObiektu
   End Structure
   Public Structure typeStrony
       Dim Nazwa As String
       Dim BackColor As Color
       Dim Obiekty() As typeObiektStrony
   End Structure
   Public Structure typedc
       Dim Tytu³ As String
       Dim Autor As String
       Public Edytowalny As Boolean
       Dim Strony() As typeStrony
   End Structure
   Public DC As typedc
' up there it is array in array in array...
' somewhere in the procedures of this class every array of this giant structure is redimed

Class Form1
'procedure 'Copy'
Dim d As Form2.typedc = DirectCast(Me.ActiveMdiChild, Form2).DC
Clipboard.SetDataObject(d.Strony(Akt).Obiekty(AktO))

'procedure 'Paste'
Dim d As Form2.typedc = DirectCast(Me.ActiveMdiChild, Form2).DC
Dim lo As Integer = d.Strony(Akt).Obiekty.Length
ReDim Preserve d.Strony(Akt).Obiekty(lo)
'here Your code
Dim cbData As DataObject = Clipboard.GetDataObject()
If cbData.GetDataPresent(GetType(Form2.typeObiektStrony).ToString) Then
    d.Strony(Akt).Obiekty(lo) = cbData.GetData(GetType(Form2.typeObiektStrony).ToString, True)
End If
DirectCast(Me.ActiveMdiChild, Form2).DC = d

 

There is no error, but new array of Obiekt should be created, and it is, but with every sub array and data set to Nothing. I realy don't get it.

 

Thank You for help...

  • *Experts*
Posted

You must make sure that the structure which needs to go on the

clipboard has the Serializable() attribute. Perhaps you should try

putting it on all of the Structures to see if that fixes anything.

  • *Experts*
Posted

Serializable() makes it so that the class can be converted into a form

that can be stored or transferred easily (quite often it is XML or, in

this case, binary). If the Serializable() attribute is off, then the program

has no way of putting the class into the clipboard, so you need to

turn it on.

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.

×
×
  • Create New...