تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
أريد تحويل كود من vb.net الئ C#
#1
أن كان ممكن تحويل هذا الكود الئ C#





Imports System.IO
Imports System.Runtime.InteropServices

Public Class Form1


    <DllImport("shell32.dll")> _
    Private Shared Function SHFormatDrive(ByVal hwnd As IntPtr, ByVal drive As UInteger, _
             ByVal fmtID As UInteger, ByVal options As UInteger) As ULong
    End Function


    Private Enum SHFormatFlags As Integer
        SHFMT_ID_DEFAULT = &HFFFF
        SHFMT_OPT_FULL = &H1
        SHFMT_OPT_SYSONLY = &H2
        SHFMT_ERROR = &HFFFFFFFF
        SHFMT_CANCEL = &HFFFFFFFE
        SHFMT_NOFORMAT = &HFFFFFFD
        SHFD_FORMAT_FULL = 0   ' full format
        SHFD_FORMAT_QUICK = 1  ' quick format
    End Enum

    Private Sub FButton_Click_1(sender As System.Object, e As System.EventArgs) Handles FButton.Click
        If CBoxDrives.Text = "" Then
            MsgBox("No Drive Selected")
            Exit Sub
        End If
        Dim Iresult As ULong = SHFormatDrive(CType(Me.Handle.ToInt32, IntPtr), CUInt(Asc(CBoxDrives.Text.Substring(0, 1)) - Asc("A")), CUInt(SHFormatFlags.SHFMT_ID_DEFAULT), 1)
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        With FButton
        End With
        Me.Controls.Add(FButton)
        With CBoxDrives
            .DropDownStyle = ComboBoxStyle.DropDown
        End With
        Me.Controls.Add(CBoxDrives)

        Dim DrivesFound As Integer = 0
        Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
        Dim d As DriveInfo
        For Each d In allDrives
            If ((d.DriveType = DriveType.Fixed) Or (d.DriveType = DriveType.Removable)) AndAlso Environment.GetEnvironmentVariable("SYSTEMROOT").StartsWith(d.Name) = False Then
                CBoxDrives.Items.Add(d.Name)
                DrivesFound += 1
            End If
        Next
        CBoxDrives.SelectedIndex = DrivesFound - 1
    End Sub
End Class
الرد }}}
تم الشكر بواسطة:
#2
تفضل الكود بعد التحويل
فى البداية سيتم التاكد من اسدعاء التالى
كود :
using System.IO;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

لا تنسي اضافة Microsoft.VisualBasic من خلال References

الان تقوم باضافة الكود التالى خارج اى حدث
كود :
       [DllImport("shell32.dll")]
       private static extern ulong SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);

       private enum SHFormatFlags : int
       {
           SHFMT_ID_DEFAULT = 0xFFFF,
           SHFMT_OPT_FULL = 0x1,
           SHFMT_OPT_SYSONLY = 0x2,
           SHFMT_ERROR = 0xFFFFFFF,
           SHFMT_CANCEL = 0xFFFFFFE,
           SHFMT_NOFORMAT = 0xFFFFFFD,
           SHFD_FORMAT_FULL = 0,   // full format
           SHFD_FORMAT_QUICK = 1  // quick format
       }

فى حدث الزر قم باضافة الكود التالى
كود :
           if (CBoxDrives.Text == "")
           {
               MessageBox.Show("No Drive Selected");
               return;
           }
           ulong Iresult = SHFormatDrive(this.Handle.ToInt32, Convert.ToUInt32((char)(CBoxDrives.Text.Substring(0, 1)) - Strings.Asc("A")), System.Convert.ToUInt32(SHFormatFlags.SHFMT_ID_DEFAULT), 1);

وبالنهاية فى حدث لود الفورم قم باضافة الكود التالى
كود :
           var FBlock = FButton;
           this.Controls.Add(FBlock);
           var CBlock = CBoxDrives;
           CBlock.DropDownStyle = ComboBoxStyle.DropDown;
           this.Controls.Add(CBoxDrives);

           int DrivesFound = 0;
           DriveInfo[] allDrives = DriveInfo.GetDrives();
           foreach (DriveInfo d in allDrives)
           {
               if (((d.DriveType == DriveType.Fixed) | (d.DriveType == DriveType.Removable)) && Environment.GetEnvironmentVariable("SYSTEMROOT").StartsWith(d.Name) == false)
               {
                   CBoxDrives.Items.Add(d.Name);
                   DrivesFound += 1;
               }
           }
           CBoxDrives.SelectedIndex = DrivesFound - 1;

كل ما تبقي عليك هو تغيير المسميات طبقاً لكل اسم اداء مستخدم لديك
والاسماء التى مطلوب النظر اليها
PHP كود :
CBoxDrivesFButton 

وتذكر بان FButton هو خاص بحدث الزر
الرد }}}
#3
(21-09-19, 06:28 PM)kiki كتب : تفضل الكود بعد التحويل
فى البداية سيتم التاكد من اسدعاء التالى
كود :
using System.IO;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

لا تنسي اضافة Microsoft.VisualBasic من خلال References

الان تقوم باضافة الكود التالى خارج اى حدث
كود :
       [DllImport("shell32.dll")]
       private static extern ulong SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);

       private enum SHFormatFlags : int
       {
           SHFMT_ID_DEFAULT = 0xFFFF,
           SHFMT_OPT_FULL = 0x1,
           SHFMT_OPT_SYSONLY = 0x2,
           SHFMT_ERROR = 0xFFFFFFF,
           SHFMT_CANCEL = 0xFFFFFFE,
           SHFMT_NOFORMAT = 0xFFFFFFD,
           SHFD_FORMAT_FULL = 0,   // full format
           SHFD_FORMAT_QUICK = 1  // quick format
       }

فى حدث الزر قم باضافة الكود التالى
كود :
           if (CBoxDrives.Text == "")
           {
               MessageBox.Show("No Drive Selected");
               return;
           }
           ulong Iresult = SHFormatDrive(this.Handle.ToInt32, Convert.ToUInt32((char)(CBoxDrives.Text.Substring(0, 1)) - Strings.Asc("A")), System.Convert.ToUInt32(SHFormatFlags.SHFMT_ID_DEFAULT), 1);

وبالنهاية فى حدث لود الفورم قم باضافة الكود التالى
كود :
           var FBlock = FButton;
           this.Controls.Add(FBlock);
           var CBlock = CBoxDrives;
           CBlock.DropDownStyle = ComboBoxStyle.DropDown;
           this.Controls.Add(CBoxDrives);

           int DrivesFound = 0;
           DriveInfo[] allDrives = DriveInfo.GetDrives();
           foreach (DriveInfo d in allDrives)
           {
               if (((d.DriveType == DriveType.Fixed) | (d.DriveType == DriveType.Removable)) && Environment.GetEnvironmentVariable("SYSTEMROOT").StartsWith(d.Name) == false)
               {
                   CBoxDrives.Items.Add(d.Name);
                   DrivesFound += 1;
               }
           }
           CBoxDrives.SelectedIndex = DrivesFound - 1;

كل ما تبقي عليك هو تغيير المسميات طبقاً لكل اسم اداء مستخدم لديك
والاسماء التى مطلوب النظر اليها
PHP كود :
CBoxDrivesFButton 

وتذكر بان FButton هو خاص بحدث الزر


طلعلي غلط بالكود الأخير
https://www.up-00.com/2zloyx1jeoxg

(21-09-19, 06:28 PM)kiki كتب : تفضل الكود بعد التحويل
فى البداية سيتم التاكد من اسدعاء التالى
كود :
using System.IO;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

لا تنسي اضافة Microsoft.VisualBasic من خلال References

الان تقوم باضافة الكود التالى خارج اى حدث
كود :
       [DllImport("shell32.dll")]
       private static extern ulong SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);

       private enum SHFormatFlags : int
       {
           SHFMT_ID_DEFAULT = 0xFFFF,
           SHFMT_OPT_FULL = 0x1,
           SHFMT_OPT_SYSONLY = 0x2,
           SHFMT_ERROR = 0xFFFFFFF,
           SHFMT_CANCEL = 0xFFFFFFE,
           SHFMT_NOFORMAT = 0xFFFFFFD,
           SHFD_FORMAT_FULL = 0,   // full format
           SHFD_FORMAT_QUICK = 1  // quick format
       }

فى حدث الزر قم باضافة الكود التالى
كود :
           if (CBoxDrives.Text == "")
           {
               MessageBox.Show("No Drive Selected");
               return;
           }
           ulong Iresult = SHFormatDrive(this.Handle.ToInt32, Convert.ToUInt32((char)(CBoxDrives.Text.Substring(0, 1)) - Strings.Asc("A")), System.Convert.ToUInt32(SHFormatFlags.SHFMT_ID_DEFAULT), 1);

وبالنهاية فى حدث لود الفورم قم باضافة الكود التالى
كود :
           var FBlock = FButton;
           this.Controls.Add(FBlock);
           var CBlock = CBoxDrives;
           CBlock.DropDownStyle = ComboBoxStyle.DropDown;
           this.Controls.Add(CBoxDrives);

           int DrivesFound = 0;
           DriveInfo[] allDrives = DriveInfo.GetDrives();
           foreach (DriveInfo d in allDrives)
           {
               if (((d.DriveType == DriveType.Fixed) | (d.DriveType == DriveType.Removable)) && Environment.GetEnvironmentVariable("SYSTEMROOT").StartsWith(d.Name) == false)
               {
                   CBoxDrives.Items.Add(d.Name);
                   DrivesFound += 1;
               }
           }
           CBoxDrives.SelectedIndex = DrivesFound - 1;

كل ما تبقي عليك هو تغيير المسميات طبقاً لكل اسم اداء مستخدم لديك
والاسماء التى مطلوب النظر اليها
PHP كود :
CBoxDrivesFButton 

وتذكر بان FButton هو خاص بحدث الزر


طلعلي غلط بالكود الأخير

الرد }}}
تم الشكر بواسطة:
#4
قم بازالة هذه الجملة من السطر

كود :
(char)
الرد }}}
تم الشكر بواسطة: حريف برمجة , elgokr
#5
(22-09-19, 12:52 PM)kiki كتب : قم بازالة هذه الجملة من السطر

كود :
(char)

ظهر خطئ أخر

الرد }}}
تم الشكر بواسطة:
#6
بخصوص هذا الخطاء
تاكد من اضافة هذا الملف بالمشروع
Microsoft.VisualBasic
الرد }}}
تم الشكر بواسطة: asemshahen5 , حريف برمجة , elgokr
#7
(04-10-19, 03:50 PM)kiki كتب : بخصوص هذا الخطاء
تاكد من اضافة هذا الملف بالمشروع
Microsoft.VisualBasic

تم أضافه Microsoft.VisualBasic

أصبح الكود كلا أخطأء
الرد }}}
تم الشكر بواسطة: kiki , elgokr


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [C#.NET] تحويل كود ahmed_king2023 2 525 06-06-23, 09:44 AM
آخر رد: fouadhdfouad
  [VB.NET] تحويل كود ahmed_king2023 6 813 22-04-23, 11:30 PM
آخر رد: ahmed_king2023
  [C#.NET] تحويل كود الي c# ali_ahmed12 2 501 10-01-23, 03:02 PM
آخر رد: ali_ahmed12
  [C#.NET] تحويل كود الي c# ali_ahmed12 2 654 03-12-22, 03:52 PM
آخر رد: ali_ahmed12
  [VB.NET] تحويل كود الي c# ali_ahmed12 5 867 30-11-22, 07:32 PM
آخر رد: ali_ahmed12
  [VB.NET] تحويل كود الي c# ali_ahmed12 0 456 29-11-22, 06:30 PM
آخر رد: ali_ahmed12
  [C#.NET] تحويل كود تالي الي c# ali_ahmed12 5 912 17-11-22, 04:25 AM
آخر رد: yaser27
  [C#.NET] تحويل كود الي c# ali_ahmed12 2 1,021 02-11-22, 05:54 PM
آخر رد: الماجيك مسعد
  تحويل دالة ali_ahmed12 11 1,708 16-10-22, 02:32 PM
آخر رد: Meen2
  تحويل مشروع من c# الى فيجول بيسك Lathe1 3 1,414 04-06-22, 08:49 PM
آخر رد: Lathe1

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم