Список форумов New Russian America New Russian America
Самый русский форум Америки
 

C#
Click here to go to the original topic

 
       Список форумов New Russian America -> Компьютерная и бытовая
Предыдущая тема :: Следующая тема  
Автор Сообщение
Olezhik



Зарегистрирован: 03.10.2005
Сообщения: 3447
Откуда: Los Angeles, Ca

Добавлено: Пт Окт 28 11:44:17 GMT 05    Заголовок сообщения: C#  

Вот такой глупы вопрос...

Кто нибудь знает как зделать MessageBox по центру програмы, а не икрана?

Когда я пишу так, MessageBox выскакивает в центре икрана.

Код: MessageBox.Show("Message");

А мне нужно чтоб он всегда выскакивал в центре програмы. Уже 2 чяса потратил не где не нахожу ответа, на этот глупы вопрос.
Вернуться к началу  
СМЕШНО



Зарегистрирован: 04.10.2005
Сообщения: 2926

Добавлено: Пт Окт 28 22:11:07 GMT 05    Заголовок сообщения:  

Короче, пиши кастом функцию с открытием и позиционированием респонс окна, либо найди готовое.


MessageBox bug ??

Has anyone ever tried to place a messagebox at a particular position or part of the screen ? Have you noticed any weird behaviour with messageboxes in .NET ? I was recently browsing the experts-exchange site and i found a question about positioning messageboxes.

It said that owner parameter in the MessageBox's static method, is not being considered at all while showing the actual messagebox. Here's the actual syntax for the messagebox's Show method.

public static DialogResult Show( IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options );

Now say inside a WinForm's Load event, if i call

MessageBox.Show(this, "Hello World !");

where this stands for the 'owner' here of type IWin32Window, meaning that the messagebox should be the modal dialog for the current window and it should be displayed in the center of its parent. But the weirdest part is yet to kick in. For some reason, even if you pass or set this parameter, it is being ignored or not considered and only the default window or the ActiveDesktop window is being taken for the IWin32Window. So what happens is that the MessageBox always shows up in the center of the screen and not anywhere else.

I think i have found out the reason for this bug or whatever the flaw is .. The MessageBox class in System.Windows.Forms namespace has a private static method with the signature

private static DialogResult ShowCore(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)

This method basically checks whether the owner is null or not and then it calls the MessageBox function in the User32.dll ... Now if the passes owner to this function is null, then the activewindow handle is taken and passed on to the nativemethod call. The MessageBox then calls the SafeNativeMethods.MessageBox and passes the params that it has obtained which in turn is a wrapper around the system's MessageBox function.This function takes the window handle as one of its parameters but i think internally this is always pointing to the ActiveDesktop window's handle ... that is why the messagebox always ends up popping in the middle of screen instead of the middle of form ...

To test this out and to confirm it, i checked out the MsgBox function in VB and voila ! It gives the same expected behaviour of placing the messagebox right in the center of the screen and never on the activeform as the implementation should have been.

So basically unless MS changes the user32.dll this problem cannot be solved wrt messageboxes.

I feel releived on finding that this is NOT A BUG in the framework as many have suggested in some of the newsgroups !!
Вернуться к началу  
ABTOP



Зарегистрирован: 04.10.2005
Сообщения: 10737

Добавлено: Пт Окт 28 22:27:33 GMT 05    Заголовок сообщения:  

Я вот одного чёта нипанимаю... Исходя из маих харашо забытых урокаф праграмирования...
Если ты саздаёшь окно, в котором существует твоя прога, то ты же должен задать размер окна, так? Ни так подели размер пополам, введи сдвиг на положение окна на экране - получишь середину окна. Или я здорава нидаганяю вапрос?
Вернуться к началу  
СМЕШНО



Зарегистрирован: 04.10.2005
Сообщения: 2926

Добавлено: Сб Окт 29 22:11:21 GMT 05    Заголовок сообщения:  

дело в том, что месажебокс - обжект и функция стандартная, встроенная и ничего там не изменишь, она удобная и простая, а писАть свою это дольше, чем напечатать слово MessageBox.

П.С.
Размер и позиция parent окна не фиксирован, он ресайзабл. т.е. используешь X и Y.
Вернуться к началу  
Olezhik



Зарегистрирован: 03.10.2005
Сообщения: 3447
Откуда: Los Angeles, Ca

Добавлено: Пн Окт 31 11:42:58 GMT 05    Заголовок сообщения:  

Попробовал, всё равно этот грёбаны месадже не работает как положено... похоже придёца мне делать своё кустом месаджь окно... :cry:
Вернуться к началу  
СМЕШНО



Зарегистрирован: 04.10.2005
Сообщения: 2926

Добавлено: Пн Окт 31 13:41:14 GMT 05    Заголовок сообщения:  

Биг дил, странно, что оно у тебя до сих пор не сделанно. У меня даже есть SQL функция - последний бизнес день месяца. :lol: :)

Olezhik писал(а): Попробовал, всё равно этот грёбаны месадже не работает как положено... похоже придёца мне делать своё кустом месаджь окно... :cry:
Вернуться к началу  
Olezhik



Зарегистрирован: 03.10.2005
Сообщения: 3447
Откуда: Los Angeles, Ca

Добавлено: Пн Окт 31 14:14:54 GMT 05    Заголовок сообщения:  

СМЕШНО писал(а): Биг дил, странно, что оно у тебя до сих пор не сделанно. У меня даже есть SQL функция - последний бизнес день месяца. :lol: :)

Olezhik писал(а): Попробовал, всё равно этот грёбаны месадже не работает как положено... похоже придёца мне делать своё кустом месаджь окно... :cry: Просто скольо лет я писал програмы ещё никто не жаловался на таий мелочи. Ну я им сказал что в центре икрана поставить месадже бакс очень трудно и нудно. Так они согласились на такой как есть ... :D
Вернуться к началу  
 
       Список форумов New Russian America -> Компьютерная и бытовая
Страница 1 из 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.22 © 2001, 2002 phpBB Group