Visual Studio C# ile arka planı değiştiren program nasıl kodlanır?

Senyorr

Decapat
Katılım
21 Kasım 2021
Mesajlar
133
Çözümler
1
Daha fazla  
Sistem Özellikleri
Rtx2060s Ryzen53600 HyperFurryX8x2 AsusB450MAProMax
Cinsiyet
Erkek
Meslek
Öğrenci
Butona bastığımda istediğim fotoğrafı koyacak, sonra da kaldıracak bir kod lazım.
Yeni başladım.
 
Son düzenleyen: Moderatör:
C#:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Wallpapercheee
{
    public partial class MainForm : Form
    {
        const int SPI_SETDESKWALLPAPER = 0x0014;
        const int SPIF_UPDATEINIFILE = 0x01;
        const int SPIF_SENDCHANGE = 0x02;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

        public MainForm()
        {
            InitializeComponent();
            InitializeUI();
        }

        private void InitializeUI()
        {
            Text = "Wallpaper Changer";
            Size = new System.Drawing.Size(300, 200);

            Button changeWallpaperButton = new Button();
            changeWallpaperButton.Text = "Arkaplanı Değiştir";
            changeWallpaperButton.Click += ChangeWallpaperButton_Click;
            Controls.Add(changeWallpaperButton);
        }

        private void ChangeWallpaperButton_Click(object sender, EventArgs e)
        {
            //dosya yolu
            string imagePath = @"C:\Path\To\Your\Image.jpg";

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
        }
    }

}
 
using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; class Program { const int SPI_SETDESKWALLPAPER = 0x0014; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDCHANGE = 0x02; [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form form = new Form(); Button changeWallpaperButton = new Button(); changeWallpaperButton.Text = "Arkaplanı Değiştir"; changeWallpaperButton.Click += ChangeWallpaperButton_Click; form.Controls.Add(changeWallpaperButton); Application.Run(form); } private static void ChangeWallpaperButton_Click(object sender, EventArgs e) { // İstediğiniz fotoğrafın yolunu aşağıdaki satıra ekleyin string imagePath = @"C:\Path\To\Your\Image.jpg"; // Masaüstü arkaplanını değiştir SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); // Belirli bir süre sonra orijinal arkaplana geri dön Thread.Sleep(5000); // Örnek olarak 5 saniye bekletme süresi SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } }

Başlangıç için yeterli bir kod. Kodu iyice geliştirebilirsin.
 
using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; class Program. { const int SPI_SETDESKWALLPAPER = 0x0014; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDCHANGE = 0x02; [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form form = new Form(); Button changeWallpaperButton = new Button(); changeWallpaperButton.Text = "Arkaplanı Değiştir"; changeWallpaperButton.Click += ChangeWallpaperButton_Click; form.Controls.Add(changeWallpaperButton); Application.Run(form); } private static void ChangeWallpaperButton_Click(object sender, EventArgs e) { // İstediğiniz fotoğrafın yolunu aşağıdaki satıra ekleyin. string imagePath = @"C:\Path\To\Your\Image.jpg"; // Masaüstü arkaplanını değiştir. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); // Belirli bir süre sonra orijinal arkaplana geri dön. Thread.Sleep(5000); // Örnek olarak 5 saniye bekletme süresi. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } }

Başlangıç için yeterli bir kod. Kodu iyice geliştirebilirsin.

Zor anlaşılıyor hocam.
 
Hiçbir şey anlamadım sadece butona bastığımda form1'in arka planı image ile değişecek.
Altta belirtmemişim detayı kusura bakmayın ama yeniyim derken çok yeniyim.
 
using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; class Program { const int SPI_SETDESKWALLPAPER = 0x0014; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDCHANGE = 0x02; [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form form = new Form(); Button changeWallpaperButton = new Button(); changeWallpaperButton.Text = "Arkaplanı Değiştir"; changeWallpaperButton.Click += ChangeWallpaperButton_Click; form.Controls.Add(changeWallpaperButton); Application.Run(form); } private static void ChangeWallpaperButton_Click(object sender, EventArgs e) { // İstediğiniz fotoğrafın yolunu aşağıdaki satıra ekleyin string imagePath = @"C:\Path\To\Your\Image.jpg"; // Masaüstü arkaplanını değiştir SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); // Belirli bir süre sonra orijinal arkaplana geri dön Thread.Sleep(5000); // Örnek olarak 5 saniye bekletme süresi SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } }

Başlangıç için yeterli bir kod. Kodu iyice geliştirebilirsin.
Formun arkaplanı demiş.

Hiçbir şey anlamadım sadece butona bastığımda form1'in arka planı image ile değişecek.
Altta belirtmemişim detayı kusura bakmayın ama yeniyim derken çok yeniyim.
Ben basitçe yazayım herhalde yeni başladınız yazılıma;
Öncelikle resourcese bir resim yükleyin.
Sonra ise hangi butona tıklanılınca değişecekse forma gelip o butona çift tıklayın.
Açılan pencere kod penceresi oraya şu kodu girin;
C#:
this.BackgroundImage = Properties.Resources.resminismi; //resminismi yazan yere resmin ismini gir.

Hocam temel konseptleri öğrenmeye başla o vakit.
Kodu siz tam yazamamışsınız. Bir kere yazarken hatanız var o yüzdende anlaşılamıyor.
1701168349897.png

Kodu yazarken bu butona tıklayıp
1701168383030.png

Buraya girin kodu. Sosyal'de nasıl kod paylaşılır?
 

Yeni konular

Geri
Yukarı