IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual Studio Discussion :

Ajuster l'éclairage Possible ?


Sujet :

Visual Studio

  1. #1
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut Ajuster l'éclairage Possible ?
    Bonjour tous le monde

    Après avoir trouvé une solution pour éteindre Windows via VS, je souhaite pouvoir réduire la luminosité au minimum ou l'augmenter au max selon une action.

    Cependant je n'ai pas réussi à trouver de code sur ce thème, y'a t-il un moyen de le faire ?

    Merci à vous,

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    à googler : wmi change brightness c#
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    Merci, j'ai donc trouvé ce petit programme https://www.codeproject.com/Articles...ps-and-Tablets ,le seul qui ne joue pas sur les couleurs mais bien l'éclairage.

    Je n'ai pas réussi à modifier ce programme C+ pour l'ajouter au mien (.vb) et sans 'icon de notification'

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
    namespace ScreenBrightness
    {
        public partial class Form1 : Form
        {
            int iCount = 0; //global counter for hiding/closing form after certian period of inactivity
            byte[] bLevels; //array of valid level values
            string[] arguments; 
     
            public Form1(string[]args)
            {
                arguments = args;
                InitializeComponent();
            }
     
            //In case of an incompatible system, the form has to be shown in order to close the app...as far as I know ^^
            private void Form1_Shown(object sender, EventArgs e)
            {
                bLevels = GetBrightnessLevels(); //get the level array for this system
                if (bLevels.Count() == 0) //"WmiMonitorBrightness" is not supported by the system
                {
                    Application.Exit();
                }
                else
                {
                    trackBar1.TickFrequency = bLevels.Count(); //adjust the trackbar ticks according the number of possible brightness levels
                    trackBar1.Maximum = bLevels.Count() - 1;
                    trackBar1.Update();
                    trackBar1.Refresh();
                    check_brightness();
                    timer1.Enabled = true;  //timer for closing form
                    //check the arguments
                    if (Array.FindIndex(arguments, item => item.Contains("%") ) > -1)
                        startup_brightness();
                    if (arguments.Length == 0 || Array.IndexOf(arguments, "hide")>-1) //hide the trackbar initially if no arguments are passed
                        this.Hide();
     
                }
            }
            private void check_brightness()
            {
                    int iBrightness = GetBrightness(); //get the actual value of brightness
                    int i = Array.IndexOf(bLevels, (byte)iBrightness); 
                    if (i < 0) i = 1;
                    change_icon(iBrightness); 
                    trackBar1.Value = i;
            }
     
            private void startup_brightness()
            {
                string sPercent = arguments[Array.FindIndex(arguments, item => item.Contains("%"))];
                if (sPercent.Length > 1)
                {
                    int iPercent = Convert.ToInt16(sPercent.Split('%').ElementAt(0));
                    if (iPercent >= 0 && iPercent <= bLevels[bLevels.Count() - 1])
                    {
                        byte level =100;
                        foreach (byte item in bLevels)
                        {
                            if (item >= iPercent)
                            {
                                level = item;
                                break;
                            }
                        }
                        SetBrightness(level);
                        check_brightness();
                    }
     
                }
            }
     
            //change the icon according to brightness
            private void change_icon(int iBrightness)
            {
                if (iBrightness < 25)  
                    pictureBox1.Image = ScreenBrightness.Properties.Resources.sonne_2;
                else
                {
                    if (iBrightness < 75)
                        pictureBox1.Image = ScreenBrightness.Properties.Resources.sonne_1;
                    else
                        pictureBox1.Image = ScreenBrightness.Properties.Resources.sonne;
                }
                label1.Text = iBrightness.ToString() + "%";
            }
     
            private void trackBar1_Scroll(object sender, EventArgs e)
            {
                SetBrightness(bLevels[trackBar1.Value]);
                change_icon(bLevels[trackBar1.Value]);
                iCount = 0; //reset inactivity counter
            }
     
     
     
            //get the actual percentage of brightness
            static int GetBrightness()
            {
                //define scope (namespace)
                System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI");
     
                //define query
                System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness");
     
                //output current brightness
                System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);
     
                System.Management.ManagementObjectCollection moc = mos.Get();
     
                //store result
                byte curBrightness = 0;
                foreach (System.Management.ManagementObject o in moc)
                {
                    curBrightness = (byte)o.GetPropertyValue("CurrentBrightness");
                    break; //only work on the first object
                }
     
                moc.Dispose();
                mos.Dispose();
     
                return (int)curBrightness;
            }
     
            //array of valid brightness values in percent
            static byte[] GetBrightnessLevels()
            {
                //define scope (namespace)
                System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI");
     
                //define query
                System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness");
     
                //output current brightness
                System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);
                byte[] BrightnessLevels = new byte[0];
     
                try
                {
                    System.Management.ManagementObjectCollection moc = mos.Get();
     
                        //store result
     
     
                    foreach (System.Management.ManagementObject o in moc)
                    {
                        BrightnessLevels = (byte[])o.GetPropertyValue("Level");
                        break; //only work on the first object
                    }
     
                    moc.Dispose();
                    mos.Dispose();
     
                }
                catch (Exception)
                {
                    MessageBox.Show("Sorry, Your System does not support this brightness control...");
     
                }
     
                return BrightnessLevels;
            }
     
            static void SetBrightness(byte targetBrightness)
            {
                //define scope (namespace)
                System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI");
     
                //define query
                System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods");
     
                //output current brightness
                System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);
     
                System.Management.ManagementObjectCollection moc = mos.Get();
     
                foreach (System.Management.ManagementObject o in moc)
                {
                    o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise!
                    break; //only work on the first object
                }
     
                moc.Dispose();
                mos.Dispose();
            }
     
            //timer for hiding/closing form
            private void timer1_Tick(object sender, EventArgs e)
            {
                iCount++;
                if(iCount > 2)
                {
                    if (Array.IndexOf(arguments, "quit") > -1)
                        this.Close();
                    else
                    {
                        this.Hide();
                        timer1.Stop();
                        iCount = 0;
                    }
     
                }
            }
     
            private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    Point p = new Point(MousePosition.X, MousePosition.Y);
                    Rectangle r = Screen.GetBounds(p);
                    //find the right position next to the icon
                    if (p.X > r.Width / 2)
                    {
                        if (p.X + 140 > r.Width)
                            this.Left = r.Width - 275;
                        else
                            this.Left = p.X - 140;
                    }
                    else
                        this.Left = p.X;
     
                    if (p.Y > r.Height / 2)
                        this.Top = p.Y - 60;
                    else
                        this.Top = p.Y;
                    check_brightness();
                    this.Show();
                    this.Activate();
                    timer1.Start();
                }
                else
                    contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
     
            }
     
            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                this.Close();
            }
     
            private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
            {
                notifyIcon1.Text = "screen brightness " + GetBrightness().ToString() + "%";
            }
     
        }
    }
    Pourriez-vous m'aidez ?

  4. #4
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    traducteur c# / vb.net :
    http://converter.telerik.com/
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    Merci, Mais ce n'est pas vraiment la traduction qui me bloque, c'est par rapport au faite qu'il soit programmé pour être un icon que je n'arrive pas à retirer.

    Le code retraduit .vb :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
     
     
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Linq
    Imports System.Text
    Imports System.Windows.Forms
     
    Namespace ScreenBrightness
        Partial Public Class Form1
            Inherits Form
            Private iCount As Integer = 0
            'global counter for hiding/closing form after certian period of inactivity
            Private bLevels As Byte()
            'array of valid level values
            Private arguments As String()
     
            Public Sub New(args As String())
                arguments = args
                InitializeComponent()
            End Sub
     
            'In case of an incompatible system, the form has to be shown in order to close the app...as far as I know ^^
            Private Sub Form1_Shown(sender As Object, e As EventArgs)
                bLevels = GetBrightnessLevels()
                'get the level array for this system
                If bLevels.Count() = 0 Then
                    '"WmiMonitorBrightness" is not supported by the system
                    Application.[Exit]()
                Else
                    trackBar1.TickFrequency = bLevels.Count()
                    'adjust the trackbar ticks according the number of possible brightness levels
                    trackBar1.Maximum = bLevels.Count() - 1
                    trackBar1.Update()
                    trackBar1.Refresh()
                    check_brightness()
                    timer1.Enabled = True
                    'timer for closing form
                    'check the arguments
                    If Array.FindIndex(arguments, Function(item) item.Contains("%")) > -1 Then
                        startup_brightness()
                    End If
                    If arguments.Length = 0 OrElse Array.IndexOf(arguments, "hide") > -1 Then
                        'hide the trackbar initially if no arguments are passed
                        Me.Hide()
     
                    End If
                End If
            End Sub
            Private Sub check_brightness()
                Dim iBrightness As Integer = GetBrightness()
                'get the actual value of brightness
                Dim i As Integer = Array.IndexOf(bLevels, CByte(iBrightness))
                If i < 0 Then
                    i = 1
                End If
     
                TrackBar1.Value = i
            End Sub
     
            Private Sub startup_brightness()
                Dim sPercent As String = arguments(Array.FindIndex(arguments, Function(item) item.Contains("%")))
                If sPercent.Length > 1 Then
                    Dim iPercent As Integer = Convert.ToInt16(sPercent.Split("%"c).ElementAt(0))
                    If iPercent >= 0 AndAlso iPercent <= bLevels(bLevels.Count() - 1) Then
                        Dim level As Byte = 100
                        For Each item As Byte In bLevels
                            If item >= iPercent Then
                                level = item
                                Exit For
                            End If
                        Next
                        SetBrightness(level)
                        check_brightness()
     
                    End If
                End If
            End Sub
     
     
     
            Private Sub trackBar1_Scroll(sender As Object, e As EventArgs)
                SetBrightness(bLevels(trackBar1.Value))
     
                iCount = 0
                'reset inactivity counter
            End Sub
     
     
     
            'get the actual percentage of brightness
            Private Shared Function GetBrightness() As Integer
                'define scope (namespace)
                Dim s As New System.Management.ManagementScope("root\WMI")
     
                'define query
                Dim q As New System.Management.SelectQuery("WmiMonitorBrightness")
     
                'output current brightness
                Dim mos As New System.Management.ManagementObjectSearcher(s, q)
     
                Dim moc As System.Management.ManagementObjectCollection = mos.[Get]()
     
                'store result
                Dim curBrightness As Byte = 0
                For Each o As System.Management.ManagementObject In moc
                    curBrightness = CByte(o.GetPropertyValue("CurrentBrightness"))
                    'only work on the first object
                    Exit For
                Next
     
                moc.Dispose()
                mos.Dispose()
     
                Return CInt(curBrightness)
            End Function
     
            'array of valid brightness values in percent
            Private Shared Function GetBrightnessLevels() As Byte()
                'define scope (namespace)
                Dim s As New System.Management.ManagementScope("root\WMI")
     
                'define query
                Dim q As New System.Management.SelectQuery("WmiMonitorBrightness")
     
                'output current brightness
                Dim mos As New System.Management.ManagementObjectSearcher(s, q)
                Dim BrightnessLevels As Byte() = New Byte(-1) {}
     
                Try
                    Dim moc As System.Management.ManagementObjectCollection = mos.[Get]()
     
                    'store result
     
     
                    For Each o As System.Management.ManagementObject In moc
                        BrightnessLevels = DirectCast(o.GetPropertyValue("Level"), Byte())
                        'only work on the first object
                        Exit For
                    Next
     
                    moc.Dispose()
     
                    mos.Dispose()
                Catch generatedExceptionName As Exception
     
                    MessageBox.Show("Sorry, Your System does not support this brightness control...")
                End Try
     
                Return BrightnessLevels
            End Function
     
            Private Shared Sub SetBrightness(targetBrightness As Byte)
                'define scope (namespace)
                Dim s As New System.Management.ManagementScope("root\WMI")
     
                'define query
                Dim q As New System.Management.SelectQuery("WmiMonitorBrightnessMethods")
     
                'output current brightness
                Dim mos As New System.Management.ManagementObjectSearcher(s, q)
     
                Dim moc As System.Management.ManagementObjectCollection = mos.[Get]()
     
                For Each o As System.Management.ManagementObject In moc
                    o.InvokeMethod("WmiSetBrightness", New [Object]() {UInt32.MaxValue, targetBrightness})
                    'note the reversed order - won't work otherwise!
                    'only work on the first object
                    Exit For
                Next
     
                moc.Dispose()
                mos.Dispose()
            End Sub
     
            'timer for hiding/closing form
            Private Sub timer1_Tick(sender As Object, e As EventArgs)
                iCount += 1
                If iCount > 2 Then
                    If Array.IndexOf(arguments, "quit") > -1 Then
                        Me.Close()
                    Else
                        Me.Hide()
                        timer1.[Stop]()
                        iCount = 0
     
                    End If
                End If
            End Sub
     
            Private Sub notifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs)
                If e.Button = System.Windows.Forms.MouseButtons.Left Then
                    Dim p As New Point(MousePosition.X, MousePosition.Y)
                    Dim r As Rectangle = Screen.GetBounds(p)
                    'find the right position next to the icon
                    If p.X > r.Width / 2 Then
                        If p.X + 140 > r.Width Then
                            Me.Left = r.Width - 275
                        Else
                            Me.Left = p.X - 140
                        End If
                    Else
                        Me.Left = p.X
                    End If
     
                    If p.Y > r.Height / 2 Then
                        Me.Top = p.Y - 60
                    Else
                        Me.Top = p.Y
                    End If
                    check_brightness()
                    Me.Show()
                    Me.Activate()
                    timer1.Start()
                End If
     
            End Sub
     
            Private Sub exitToolStripMenuItem_Click(sender As Object, e As EventArgs)
                Me.Close()
            End Sub
     
     
            Friend WithEvents TrackBar1 As TrackBar
     
            Private Sub InitializeComponent()
                Me.components = New System.ComponentModel.Container()
                Me.TrackBar1 = New System.Windows.Forms.TrackBar()
                Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
                CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
                Me.SuspendLayout()
                '
                'TrackBar1
                '
                Me.TrackBar1.Location = New System.Drawing.Point(12, 21)
                Me.TrackBar1.Name = "TrackBar1"
                Me.TrackBar1.Size = New System.Drawing.Size(260, 45)
                Me.TrackBar1.TabIndex = 0
                '
                'Form1
                '
                Me.ClientSize = New System.Drawing.Size(284, 72)
                Me.Controls.Add(Me.TrackBar1)
                Me.Name = "Form1"
                CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
                Me.ResumeLayout(False)
                Me.PerformLayout()
     
            End Sub
     
            Friend WithEvents Timer1 As Timer
            Private components As IContainer
        End Class
    End Namespace
    Les "System.Management...." ne sont pas reconnue ici en .vb, je ne sais pas pourquoi. En C+ j'ai retiré le "Private Sub notifyIcon1" et "Private Sub exitTool" mais plus rien ne fonctionne.

  6. #6
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    ce n'est pas C+ mais C#

    il ne faut pas copier coller du code, il faut l'adapter, pour ca il faut connaitre un peu le langage et comprendre le code d'origine

    pour system.management il faut ajouter la référence au projet (c'est une dll et il faut préciser qu'on veut l'utiliser)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  7. #7
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    Pour le moment je fais juste le programme complet en .vb mais sans la partie 'icon"

    Avec :

    Imports System.Management
    Imports System.Management.Instrumentation
    ?

    J'ai essayé ça n'a pas changé.Il me donne un correction pour l'un deux mais donne plus de soucis (sur les autres System.)

  8. #8
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  9. #9
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    Merci, je ne l'ai pas sur le clic droit mais j'ai pue le trouver quand même. j'ai donc ajouté "System.Management" ce qui n'a rien fait la 1ère fois et la 2ème à retiré les "System.Management" souligner.

    J'ai donc démarrer la simulation mais la Form1 ne correspond pas à celui créer et sans le trackbar1 pourquoi ?

  10. #10
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    J'ai fini par trouver ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    Imports System.Management
     
    Public Class Form1
        Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
            Dim mclass As New ManagementClass("WmiMonitorBrightnessMethods")
            mclass.Scope = New ManagementScope("\\.\root\wmi")
            Dim instances As ManagementObjectCollection = mclass.GetInstances
     
            For Each instance As ManagementObject In instances
                Dim timeout As ULong = 1
                Dim brightness As UShort = CUShort(TrackBar1.Value * 10)
                Dim args As Object() = New Object() {timeout, brightness}
                instance.InvokeMethod("wmiSetBrightness", args)
            Next
        End Sub
    End Class
    Bien fonctionnel

    Merci

  11. #11
    Candidat au Club
    Homme Profil pro
    ouvrier
    Inscrit en
    Septembre 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : ouvrier

    Informations forums :
    Inscription : Septembre 2017
    Messages : 13
    Points : 3
    Points
    3
    Par défaut
    Je l'ai donc ajusté à mon programme pour qu'il soit modifié par rapport à ce que je reçois du Serial.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    Private Sub SerialPort1_DataReceived(sender As System.Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            ReceivedText(SerialPort1.ReadExisting())
        End Sub
     
        Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting'
            Dim mclass As New ManagementClass("WmiMonitorBrightnessMethods")
            mclass.Scope = New ManagementScope("\\.\root\wmi")
            Dim instances1 As ManagementObjectCollection = mclass.GetInstances
            Dim instances2 As ManagementObjectCollection = mclass.GetInstances
     
            If Me.RichTextBox2.InvokeRequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.Invoke(x, New Object() {(text)})
            Else
                Me.RichTextBox2.Text &= [text] 'append text'
            End If
     
            If (text) = "turnoff" Then
                Shell("shutdown -s -t 120")
            End If
     
            If (text) = "BMIN" Then
                For Each instance1 As ManagementObject In instances1
                    Dim timeout As ULong = 1
                    Dim brightness1 As UShort = CUShort(20)
                    Dim args As Object() = New Object() {timeout, brightness1}
                    instance1.InvokeMethod("wmiSetBrightness", args)
                Next
            End If
     
            If (text) = "BMAX" Then
                    For Each instance2 As ManagementObject In instances2
                        Dim timeout As ULong = 1
                        Dim brightness2 As UShort = CUShort(80)
                        Dim args As Object() = New Object() {timeout, brightness2}
                        instance2.InvokeMethod("wmiSetBrightness", args)
                    Next
                End If
        End Sub
    Merci

Discussions similaires

  1. Réponses: 2
    Dernier message: 28/04/2015, 12h25
  2. Application 'classique' possible en java ?
    Par jeanphy dans le forum JBuilder
    Réponses: 3
    Dernier message: 26/03/2003, 22h24
  3. directx et java?? possible??
    Par jiraiya dans le forum DirectX
    Réponses: 3
    Dernier message: 09/07/2002, 19h55
  4. [CR] Est il possible de créer des univers avec Seagate Info?
    Par Frank dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 27/06/2002, 15h22
  5. MDI sans MFC, possible ?
    Par delire8 dans le forum MFC
    Réponses: 4
    Dernier message: 17/06/2002, 07h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo