raynor009 Posted November 12, 2012 Report Share Posted November 12, 2012 Am reusit sa traduc un program din C# in VB.NET aproapre perfect, dar m-am blocat undeva si mai am 3 erori de rezolvat. Vreau sa spun ca nu am mai facut de mult programe si am c-am uitat, so please take it easy..rar (35,66 KB) - uploaded.toErorile sunt urmatoarele:Error 3 'Namespace' statement must end with a matching 'End Namespace'. Error 2 'Namespace' statements can occur only at file or namespace level. Error 1 'Class' statement must end with a matching 'End Class'. codu tradus in vb.netImports SystemImports System.DrawingImports System.Drawing.ImagingImports System.Windows.FormsPublic Class frmMain Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Namespace TempGraphic Public Class frmMain Inherits Form Public Sub New() MyBase.New() InitializeComponent() Me.CreateImage("") End Sub Private Sub CreateImage(ByVal text As String) Dim lines() As String = text.Split(New String() {"" & vbCrLf}, StringSplitOptions.RemoveEmptyEntries) If ((lines.Length > 0) _ AndAlso (lines.Length < 4)) Then Dim font As Font = New Font("Tahoma", 8, FontStyle.Bold) Dim bmp As Bitmap = New Bitmap(1, 1) Dim w As Integer = 0 Dim g As Graphics = Graphics.FromImage(bmp) For Each line As String In lines Dim tmpsize As SizeF = g.MeasureString(line, font, 90) If (tmpsize.Width > w) Then w = CType(tmpsize.Width, Integer) End If Next bmp = New Bitmap((w + 10), (25 _ + ((lines.Length - 1) _ * (lines.Length > 1)))) Dim g As Graphics = Graphics.FromImage(bmp) Dim x As Integer = 1 Do While (x < bmp.Width) Dim y As Integer = 1 Do While (y < bmp.Height) If (((x = 1) _ OrElse (y = 1)) _ OrElse ((x _ = (bmp.Width - 1)) _ OrElse (y _ = (bmp.Height - 1)))) Then bmp.SetPixel(x, y, Color.White) Else bmp.SetPixel(x, y, Color.FromArgb(104, 36, 96)) End If y = (y + 1) Loop x = (x + 1) Loop Dim l As Integer = 0 For Each line As String In lines g.DrawString(line, font, Brushes.White, 5, (5 _ + (l * 15))) l = (l + 1) Next Me.pictureBox1.Image = CType(bmp, Image) Me.button1.Enabled = True Else Me.pictureBox1.Image = Nothing Me.button1.Enabled = False End If End Sub End Classcodu orignalusing System;using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;namespace TempGraphic{ public partial class frmMain : Form { public frmMain() { InitializeComponent(); this.CreateImage( "" ); } void CreateImage( string text ) { string[] lines = text.Split( new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries ); if( lines.Length > 0 && lines.Length < 4 ) { Font font = new Font( "Tahoma", 8, FontStyle.Bold ); Bitmap bmp = new Bitmap( 1, 1 ); int w = 0; using( Graphics g = Graphics.FromImage( bmp ) ) { foreach( string line in lines ) { SizeF tmpsize = g.MeasureString( line, font, 90 ); if( tmpsize.Width > w ) w = (int)tmpsize.Width; } } bmp = new Bitmap( w+10, 25 + ((lines.Length - 1) * (lines.Length > 1 ? 15 : 0)) ); using( Graphics g = Graphics.FromImage( bmp )) { for( int x = 1; x < bmp.Width; x++ ) { for( int y = 1; y < bmp.Height; y++ ) { if( (x == 1 || y == 1) || (x == bmp.Width - 1 || y == bmp.Height - 1) ) bmp.SetPixel( x, y, Color.White ); else bmp.SetPixel( x, y, Color.FromArgb( 104, 36, 96 ) ); } } int l = 0; foreach( string line in lines ) { g.DrawString( line, font, Brushes.White, 5, 5 + (l * 15) ); l++; } } this.pictureBox1.Image = (Image)bmp; this.button1.Enabled = true; } else { this.pictureBox1.Image = null; this.button1.Enabled = false; } } private void textBox1_TextChanged( object sender, EventArgs e ) { TextBox self = (TextBox)sender; this.CreateImage( self.Text ); } private void button1_Click( object sender, EventArgs e ) { if( this.pictureBox1 != null ) { DialogResult result = this.saveFileDialog1.ShowDialog(); if( result == DialogResult.OK ) { this.pictureBox1.Image.Save( this.saveFileDialog1.FileName, ImageFormat.Png ); } } } }}impreuna cu codul sursa, am pus si programul terminat din C#. Multumesc anticipat Quote Link to comment Share on other sites More sharing options...
M2G Posted November 12, 2012 Report Share Posted November 12, 2012 Declara namespace inainte de declararea clasei.Ai de doua ori Public Class frmMain, sterge-o pe cea de sub importuri. Muta Namespace TempGraphic dupa importuri.Alta data poti sa folosesti asta: Convert C# to VB.NET - A free code conversion tool - developer Fusion Quote Link to comment Share on other sites More sharing options...
raynor009 Posted November 12, 2012 Author Report Share Posted November 12, 2012 (edited) Declara namespace inainte de declararea clasei.Ai de doua ori Public Class frmMain, sterge-o pe cea de sub importuri. Muta Namespace TempGraphic dupa importuri.Alta data poti sa folosesti asta: Convert C# to VB.NET - A free code conversion tool - developer FusionWow chiar nu stiam ca exista convertoare pentru asa ceva pana acuma! Mersi ca mi-ai spus, inveti ceva nou in fiecare zi.EDIT: Of ce aproape sunt, am reusit sa fac sa apara imaginea in picturebox dar nu apare si textu Edited November 12, 2012 by raynor009 Quote Link to comment Share on other sites More sharing options...