vbdotnet.it

Tricks & tips, workaround, forum and ideas with .Net

About the author

Enrico Rossini è il gestore di questo blog.
E-mail me Send mail

Recent posts

Recent comments

Contributi

Best 6 ~ 6 users ~ 6 comments

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce. I marchi citati sono delle rispettive aziende.

© Copyright 2010

Advertising


IIS 7 e MSCaptcha

Vorresti utilizzare su IIS7 il componente MSCaptcha ma nonostante tutti le configurazione questo non funziona. Per configurare correttamente e farlo funzionare, nella sesione system.weserver\handlers inserire le seguenti righe di codice:

<add name="MSCaptchaImage"

path="CaptchaImage.axd"

verb="GET"

type="MSCaptcha.CaptchaImageHandler, MSCaptcha"

preCondition="integratedMode,runtimeVersionv2.0" />

In allegato il controllo

Bin.zip (16,72 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,
Categories: iis | windowsform
Posted by enrico on Wednesday, May 05, 2010 8:43 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Accedere ad un file di risorsa globale in ASP.NET

Buon anno! Questo veloce tips per darvi il codice per accedere ad un elemento di una risorsa ovvero un file .resx che si trova all'interno della cartella App_GlobalResources. Ammettendo di aver creato il file Messages.resx ed aver inserito un elemento con nome Saluto, il codice da scrivere è il seguente:

Me.GetGlobalResourceObject("Messages", "Saluto").ToString

È necessario importare System.Globalization.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,
Posted by enrico on Tuesday, January 05, 2010 11:51 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Windows Mobile: rilevare la versione

Come riuscire a rilevare la versione del sistema operativo installato sul proprio palmare?

If System.Environment.OSVersion.Version.Major < 5 Then

MessageBox.Show("Versione 2003")

Else

MessageBox.Show("Versione 5.0")

End If

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, October 13, 2009 12:34 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Creare un combobox con ricerca

Per quanto hai cercato un combobox con la possibilità di ricerca? Ecco una semplice implementazione:

Private Sub CombBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        
Dim findString As String = String.Empty
        
If (Not e.KeyChar.IsLetterOrDigit(e.KeyChar, 0)) Then Exit Sub
        findString = e.KeyChar
        
With ComboBox1
            .SelectedIndex = ComboBox1.FindString(findString)
        
End With
        If ComboBox1.SelectedIndex > -1 Then e.Handled = True
End
Sub

Ciao a tutti!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, September 15, 2009 12:14 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Focus ad un TextBox

Ciao a tutti e buon Ferragosto! (a chi nn lavora). Oggi un veloce tricks: a me è capitato di dover dare il focus ad un textbox ma non compare il cursore all'interno dello stesso.

La funzione più scontata sarebbe TextBox.Focus(). Invece quella che funziona meglio è TextBox.Select(). Provate e verificate voi stessi!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Saturday, August 15, 2009 12:47 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Directory del programma

Ciao, questo è un semplice tricks. Molto spesso accade che si vuole sapere in quale directory gira il nostro programma. COn questa semplice riga lo si sa.

Private myFileName As String = System.Reflection.Assembly.GetExecutingAssembly().Location
myFileName = myFileName.Substring(0, myFileName.LastIndexOf("\"))

Attenzione. La funzione System.Reflection.Assembly.GetExecutingAssembly().Location restituisce anche il nome del file eseguibile. Per questo è stato necessario aggiungere la riga sottostante. Buon lavoro.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, July 28, 2009 12:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

L'usercontrol è in ambiente di designtime?

Se si è alle prese con la realizzazione di un Usercontrol potrebbe essere utile determinare se il componente stesso si trova in design-time (come ad esempio all’interno di un form in Visual Studio) o se è in runtime.

Per poter verificare questo basta utilizzare il seguente codice:

   1: ' verifica se il componente è in esecuzione a runtime
   2: If System.ComponentModel.LicenseManager.UsageMode = LicenseUsageMode.Runtime Then
   3:    ' esegue altro codice
   4: End If

Ciao.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, April 16, 2009 7:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Togliere lo scrollbar da un textbox quando non server

Non so se anche a voi è capitato ma mi sembra utile postarlo. Se hai un TextBox con una scrollbar e vuoi nascondere la scrollbar quando questa è inutile, come si può fare?

Ecco il codice (txtTesto è il nostro TextBox):

   1: Private Sub txtTesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTesto.TextChanged
   2:     Static busy As Boolean
   3:     If busy Then Exit Sub
   4:     busy = True
   5:  
   6:     With sender
   7:         Dim tS = TextRenderer.MeasureText(.Text, .Font)
   8:         Dim Hsb = .ClientSize.Height < tS.Height + .Font.Size
   9:         Dim Vsb = .ClientSize.Width < tS.Width
  10:  
  11:         If Hsb And Vsb Then
  12:             .ScrollBars = ScrollBars.Both
  13:         ElseIf Not Hsb And Not Vsb Then
  14:             .ScrollBars = ScrollBars.None
  15:         ElseIf Hsb And Not Vsb Then
  16:             .ScrollBars = ScrollBars.Vertical
  17:         Else
  18:             .ScrollBars = ScrollBars.Horizontal
  19:         End If
  20:     End With
  21:     busy = False
  22: End Sub

Ciao!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, April 10, 2009 1:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Leggere un file Microsoft Excel 97/2003 o 2007

La funzione che presento oggi consente di importare un foglio di Microsoft Excel in un dataset nelle versioni 97, 2003 e 2007.

 

   1: ''' <summary>
   2: ''' Reads the data from excel.
   3: ''' </summary>
   4: ''' <param name="excelfilename">The excelfilename.</param>
   5: ''' <returns></returns>
   6: Function ReadDataFromExcel(ByVal excelfilename As String) As DataSet
   7:     Dim ds As New DataSet
   8:     Dim da As OleDbDataAdapter
   9:     Dim conn As OleDbConnection
  10:  
  11:     Try
  12:         If System.IO.Path.GetExtension(excelfilename) = ".xls" Then
  13:             conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  14:         ElseIf System.IO.Path.GetExtension(excelfilename) = ".xlsx" Then
  15:             conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  16:         End If
  17:  
  18:         da = New OleDbDataAdapter("SELECT * FROM [Foglio1$]", conn)
  19:  
  20:         conn.Open()
  21:         da.Fill(ds)
  22:     Catch ex As Exception
  23:         MsgBox(ex.Message)
  24:     Finally
  25:         If conn.State = ConnectionState.Open Then
  26:             conn.Close()
  27:         End If
  28:     End Try
  29:     ReadDataFromExcel = ds
  30: End Function

Buon lavoro e ricordatevi il nostro forum!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, April 07, 2009 7:32 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Caricare 2 dfferenti report in Microsoft ReportViewer

Non so se ha te è capitato di dover caricare diversi Report fatti con il tool di Microsoft e vedersi restituire degli errori di vario tipo. Ad esempio a me è capitato che due report aventi parametri diversi mi creavano dei problemi quando li andavo a visualizzare.

Per poter risolvere il problema è necessario effettuare un refresh del report poiché sembra che il ReportViewer tenga in memoria le informazioni del report definiti durante la creazione in design-time.

Per poter risolvere il problema si possono utilizzare le seguenti righe di codice:

   1: Dim rds As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource
   2: Me.ReportViewer1.Reset()
   3: Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "report.rdlc"
   4: Me.ReportViewer1.LocalReport.DataSources.Clear()
   5: rds.Name = "nome_dataset_del_report"
   6: rds.Value = Me.CommesseAttivitaBindingSource
   7: Me.ReportViewer1.LocalReport.DataSources.Add(rds)

Buon lavoro!

P. S.: abbiamo creato il nostro forum per poter rispondere alle vostre domande. Utilizzatelo numerosi! Grazie

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Monday, March 09, 2009 7:11 PM
Permalink | Comments (0) | Post RSSRSS comment feed