Hirdetés

Új hozzászólás Aktív témák

  • szoke12

    őstag

    Sziasztok!

    Nemrég volt egy kisebb projektem, és amivel kapcsolatban írtam is ide. (egészen pontosan itt)
    Sikerült is megoldani a dolgot, és több helyen is kipróbáltam a programot, működött. De tegnap úgy jártam egy másik helyen, hogy be volt állítva két fullhd kijelző, kiterjesztett módban, és erre a kép csak a másodlagos kijelző jobb oldalán jelent meg, eltolódva. Mintha rossz kezdőpontot vett volna fel a program.

    Nem tudom, hol a bug. Lehet, inkább a windows ad neki rossz információt? Vagy én alkalmazok nem túl optimális megoldást? Elég kezdő vagyok még a témában. Bocsánat.

    Itt a kódrészlet:

    public MainWindow()
    {

    InitializeComponent();

    string path = "Alapkép";
    if (!Directory.Exists(path))
    {
    Directory.CreateDirectory(path);
    }
    string[] extensions = new string[] { ".jpg", ".jpeg", ".png" };

    bool empty = IsDirectoryEmpty(path);
    string emptyst = empty.ToString();
    emptyst = emptyst.ToLower();
    string route1 = Directory.GetCurrentDirectory();
    route1 = route1 + "\\" + path + "\\";
    DirectoryInfo jpegInfo = new DirectoryInfo(route1);
    FileInfo[] files = jpegInfo.GetFiles()
    .Where(f => extensions.Contains(f.Extension.ToLower())).ToArray();

    string route2;
    if (files.Length == 0)
    {
    route2 = "null";
    }
    else {
    var first = files[0];
    route2 = first.ToString();
    }

    if (emptyst != "true" && route2 != "null")
    {

    string route = route1 + route2;
    ImageBrush imageBrush = new ImageBrush();
    BitmapImage bgimage = new BitmapImage(new Uri(route, UriKind.Relative));
    imageBrush.ImageSource = bgimage;
    imageBrush.Stretch = Stretch.Uniform;
    this.Background = imageBrush;

    }
    else {
    ImageBrush imageBrush = new ImageBrush();
    BitmapImage bgimage = new BitmapImage(new Uri(@"pack://application:,,,/"
    + Assembly.GetExecutingAssembly().GetName().Name
    + ";component/"
    + "Images/Alapkép.jpg", UriKind.Absolute));
    imageBrush.ImageSource = bgimage;
    imageBrush.Stretch = Stretch.Uniform;
    this.Background = imageBrush;


    }
    Screen s = Screen.AllScreens[1];

    System.Drawing.Rectangle screenBounds = s.Bounds;
    this.Left = screenBounds.X;
    this.Top = screenBounds.Y;
    this.Height = screenBounds.Height;
    this.Width = screenBounds.Width;
    }

    public bool IsDirectoryEmpty(string path)
    {
    return !Directory.EnumerateFileSystemEntries(path).Any();
    }

    Ha valaki tud segíteni, azt előre is köszönöm! :R

Új hozzászólás Aktív témák

Hirdetés