Sep 25 2008

VB.NET: Erster Buchstabe als Grossbuchstabe

Tag: .NETMichael @ 8:14
Dim strValue As String = "let's test this."

MsgBox(StrConv(strValue, VbStrConv.ProperCase))

Sep 11 2008

VB.Net Copy Listview to Clipboard

Tag: .NETMichael @ 8:51
Public Sub CopyListViewToClipboard(ByVal lv As ListView)
Dim buffer As New StringBuilder

For i As Integer = 0 To lv.Columns.Count - 1
buffer.Append(lv.Columns(i).Text)
buffer.Append(vbTab)
Next

buffer.Append(vbCrLf)

For i As Integer = 0 To lv.Items.Count - 1
For j As Integer = 0 To lv.Columns.Count - 1
buffer.Append(lv.Items(i).SubItems(j).Text)
buffer.Append(vbTab)
Next

buffer.Append(vbCrLf)
Next

My.Computer.Clipboard.SetText(buffer.ToString)
End Sub

Sep 08 2008

Mit JavaScript Text markieren

Tag: JavaScriptMichael @ 12:42
/*
Marks the text in the given element (e)
*/
function markText(e) {
	// Not IE
	if (window.getSelection){
		var s = window.getSelection();

		if (s.setBaseAndExtent) {
                        // Safari

			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
		} else {
			// Firefox and Opera

			var r = document.createRange();

			r.selectNodeContents(e);
			s.removeAllRanges();

			s.addRange(r);
		}
	} else if (document.getSelection) {
		// Some older browsers

		var s = document.getSelection();
		var r = document.createRange();

		r.selectNodeContents(e);
		s.removeAllRanges();
		s.addRange(r);
	}  else if (document.selection) {
		// IE

		var r = document.body.createTextRange();

		r.moveToElementText(e);
		r.select();
	}
}

Die Funktion führt ein “Ctrl+a” auf ein zu übergebendes Dom-Objekte aus (also z.B. ein “Div”).

Sollte in allen gängigen Browsern funktionieren.


Sep 04 2008

VB.Net – Windows über Handle in den Vordergrund holen

Tag: .NETMichael @ 15:08
Public NotInheritable Class Win32Helper
<System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint:="SetForegroundWindow", CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As Boolean
End Function
End Class

Und der Aufruf:

Dim Win32Help As New Win32Helper

‘bring windows to front
If Not IntPtr.Zero.Equals(objProcess.MainWindowHandle) Then
Win32Helper.SetForegroundWindow(objProcess.MainWindowHandle)
End If

Wo bei objProcess.MainWindowHandle durch das entsprechende Window-Handle ersetzt werden muss.